I want to write a JOLT definition that loops through each object in my data array, and move the object to the "found" array if the key "parent_id" is present, but otherwise, if the "parent_id" key is not present, move the entire current object to the "notfound" array.
Example input:
{
"data": [
{
"ID1": "ID1",
"ID2": "123"
},
{
"parent_id": "xyz",
"ID1": "ID1",
"ID2": "123"
}
]
}
Expected output:
{
"notfound": [
{
"ID1": "ID1",
"ID2": "123"
}
],
"found": [
{
"parent_id": "xyz",
"ID1": "ID1",
"ID2": "123"
}
]
}
I’ve tried my hand at making the JOLT definition, but everything i’ve tried hasn’t really worked. Any help here would be greatly appreciated!
2
Answers
You can use the following spec
where conditional logic is used after determining the attribute with
notfound
case, and then get rid of that extra "notfound" parent_id.the demo on the site http://jolt-demo.appspot.com/ is
You can use this spec:
First, create a temp variable with the default
notfound
value.So if you see any
parent_id
in the objects, You can add a new valuefound
to the temp variable.If
parent_id
had any value the temp value looks like this:["found", "notfound"]
and You should always pick the first element.And in the last spec, We create the final object with
parent_id
or without it.