bazaarvoice / jolt

JSON to JSON transformation library written in Java.
Apache License 2.0
1.56k stars 329 forks source link

Merging 2 nested arrays of same type into one array #890

Open ankitravan opened 4 years ago

ankitravan commented 4 years ago

I have 2 nested arrays inside a parent array , and I need to line up the objects in each using the "employeeId" value.

Input : { "array1": [ { "array2": [ { "employeeId": 3108060, "employeeI2": 3108061 }, { "employeeId": 3107507, "employeeI2": 3108062 } ] }, { "array2": [ { "employeeId": 5018234, "employeeI2": 3108063 }, { "employeeId": 5002358, "employeeI2": 3108064 }, { "employeeId": 1630768, "employeeI2": 3108065 }, { "employeeId": 5022945, "employeeI2": 3108066 }, { "employeeId": 5005768, "employeeI2": 3108067 } ] } ] }

Required Output [ { "employeeId" : 3108060, "employeeGlobalId" : 3108061 }, { "employeeId" : 3107507, "employeeGlobalId" : 3108062 }, { "employeeId" : 5018234, "employeeGlobalId" : 3108063 }, { "employeeId" : 5002358, "employeeGlobalId" : 3108064 }, { "employeeId" : 1630768, "employeeGlobalId" : 3108065 }, { "employeeId" : 5022945, "employeeGlobalId" : 3108066 }, { "employeeId" : 5005768, "employeeGlobalId" : 3108067 } ]

niernier007 commented 4 years ago

[{ "operation": "shift", "spec": { "array1": { "": { "array2": { "": { "@": "[]" } } } }

}

}, { "operation": "shift", "spec": { "*": { "employeeId": "[&1].employeeId", "employeeI2": "[&1].employeeGlobalId" }

}

}]

ankitravan commented 4 years ago

Hi niernier007,

Could you explain how it is working for you. Because it returns null while i am trying to transform same above input with this code.