I’ve got an Array of Arrays of JSON Objects in my Jolt Transform, but I need to move the Objects up to the top level array. I’ve tried adding another Shift, but this just moves the objects into the same location, or puts the values of the two sub objects into a an array of values.
Input:
[
{
"parent_id": 1,
"passengers": [
{
"first_name": "John",
"last_name": "Smith"
},
{
"first_name": "Sarah",
"last_name": "Jones"
}
]
},
{
"parent_id": 2,
"passengers": [
{
"first_name": "Jess",
"last_name": "Smith"
},
{
"first_name": "Steve",
"last_name": "Jones"
}
]
}
]
Jolt Spec:
[
{
"operation": "shift",
"spec": {
"*": {
"passengers": {
"*": {
"@(2,parent_id)": "[&(3)].[&1].parent_id",
"$": "[&(3)].[&1].cid",
"first_name": "[&(3)].[&1].first_name",
"last_name": "[&(3)].[&1].last_name"
}
}
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"*": {
"pcid": "=concat(@(1,parent_id),'#',@(1,cid))"
}
}
}
}
]
Current Output:
[ [ {
"parent_id" : 1,
"cid" : "0",
"first_name" : "John",
"last_name" : "Smith",
"pcid" : "1#0"
}, {
"parent_id" : 1,
"cid" : "1",
"first_name" : "Sarah",
"last_name" : "Jones",
"pcid" : "1#1"
} ], [ {
"parent_id" : 2,
"cid" : "0",
"first_name" : "Jess",
"last_name" : "Smith",
"pcid" : "2#0"
}, {
"parent_id" : 2,
"cid" : "1",
"first_name" : "Steve",
"last_name" : "Jones",
"pcid" : "2#1"
} ] ]
Desired Output:
[ {
"parent_id" : 1,
"cid" : "0",
"first_name" : "John",
"last_name" : "Smith",
"pcid" : "1#0"
}, {
"parent_id" : 1,
"cid" : "1",
"first_name" : "Sarah",
"last_name" : "Jones",
"pcid" : "1#1"
}, {
"parent_id" : 2,
"cid" : "0",
"first_name" : "Jess",
"last_name" : "Smith",
"pcid" : "2#0"
}, {
"parent_id" : 2,
"cid" : "1",
"first_name" : "Steve",
"last_name" : "Jones",
"pcid" : "2#1"
} ]