I am a jolt newbie.
I have the following question, I have a JSON document structure of which may vary based on the type
property. See my example below.
{
"recipientId": "xxx",
"messages": [
{
"type": "text",
"text": "hi there!"
},
{
"type": "image",
"url": "http://example.com/image.jpg",
"preview": "http://example.com/thumbnail.jpg"
}
]
}
After transformation I would like to receive the following output:
{
"messages" : [ {
"text" : "hi there!",
"type" : "text"
}, {
"type" : "image",
"url" : "http://example.com/image.jpg",
"preview": "http://example.com/thumbnail.jpg"
} ],
"to" : "xxx"
}
Here is the spec that I came up with:
[
{
"operation": "shift",
"spec": {
"recipientId": "to",
"messages": {
"*": {
"type": "messages[&1].type",
"text": "messages[&1].text",
"url": "messages[&1].url",
"preview": "messages[&1].previewImageUrl"
}
}
}
}
]
The problem with this approach is that if I have "type": "text"
and if I also throw "preview"
property with the value, it will not make sense as the type text
should not have "preview"
property set.
So, I would like jolt to either ignore some properties based on the value of "type" property or avoid transforming such payloads.
Is there a way to do such "validations" in JOLT? The other option that I see would be validating it with Jackson type hierarchy.