bazaarvoice / jolt

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

Unable to convert group of objects into individual arrays using jolt. #1050

Closed arunsai271 closed 3 years ago

arunsai271 commented 3 years ago

Input:

{ "chain": [ { "formation": [ { "itemID": "1111", "isConsiderable": false }, { "itemID": "2222", "isConsiderable": false } ] }, { "formation": [ { "itemID": "3333", "isConsiderable": false }, { "itemID": "4444", "isConsiderable": false } ] } ] }

jolt spec:

[ { "operation": "shift", "spec": { "chain": { "": { "formation": { "": { "itemID": "productsList[].products[]" } } } } } } ]

Current output:

{ "productsList" : [ { "products" : [ "1111" ] }, { "products" : [ "2222" ] }, { "products" : [ "3333" ] }, { "products" : [ "4444" ] } ] }

Expected output:

{ "productsList" : [ { "products" : [ "1111","2222" ] }, { "products" : [ "3333" ,"4444"] } ] }

Please help me in achieving this output. I tried so many ways but no luck!

arunsai271 commented 3 years ago

Found the solution and pasted below. Issue resolved and hence closing the issue.

[ { "operation": "shift", "spec": { "chain": { "": { "formation": { "": { "itemID": "productsList[&3].products[&1]" } } } } } } ]