bazaarvoice / jolt

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

Filter Array elements #1094

Closed ulhep closed 3 years ago

ulhep commented 3 years ago

I am trying to transform following input json into a new json form:

Input json: [{ "externalProductCode": "FLOB0007", "businessDomains": [ "Option", "Allow Split" ] }, { "externalProductCode": "SOTF0011", "businessDomains": [ "Mobile", "Data", "Test Only" ] }, { "externalProductCode": "EQUI0160", "businessDomains": [ "Equipment", "Non Prod" ] } ]

Expected output: [ { "key" : "FLOB0007", "categories" : [ "Option" ] }, { "key" : "SOTF0011", "categories" : ["Mobile", "Data"] }, { "key" : "EQUI0160" "categories" : [ "Equipment" ] } ]

But, I could achieve: [ { "key" : "FLOB0007", "categories" : [ "Option", "Mobile", "Equipment" ] }, { "key" : "SOTF0011", "categories" : "Data" }, { "key" : "EQUI0160" } ]

My spec: [ { "operation": "shift", "spec": { "": { "externalProductCode": "[&1].key", "businessDomains": { "": { "Option|Equipment|Mobile|Data": { "$0": "[&2].categories" } } } } } } ]

Where am I going wrong? Please guide me.

ulhep commented 3 years ago

I made it working using following spec:

[ { "operation": "shift", "spec": { "": { "externalProductCode": "[&1].key", "businessDomains": { "": { "Option|Equipment|Mobile|Data": { "$0": "[&4].categories[]" } } } } } } ]