bazaarvoice / jolt

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

Get fields from the root element without specifying #1033

Open catalinD02 opened 4 years ago

catalinD02 commented 4 years ago

Hello,

{ "customerName": "M.M. DRUK SERWIS SPÓŁKA Z OGRANICZONĄ ODPOWIEDZIALNOŚCIĄ", "customerAge": 4, "product": [ { "brand": "Toblerone", "model": "Red", "category": "Chocolate" }, { "brand": "Milka", "model": "Lapte", "category": "Chocolate" } ], "count": "100", "timestamp": "2020.10.13.10.29.52" }

I have the following json.

JOLT Spec: [ { "operation": "shift", "spec": { "product": { "*": { "@(2,customerName)": "[&1].customerName", "@(2,customerAge)": "[&1].customerAge", "@(2,count)": "[&1].count", "@(2,timestamp)": "[&1].timestamp", "@(2,SomeDataID.Value)": "[&1].SomeDataID_Value", "brand": "[&1].product_brand", "model": "[&1].product_model", "category": "[&1].product_category" } } } }

]

Output: [ { "customerName" : "M.M. DRUK SERWIS SPÓ?KA Z OGRANICZON? ODPOWIEDZIALNO?CI?", "customerAge" : 4, "count" : "100", "timestamp" : "2020.10.13.10.29.52", "product_brand" : "Toblerone", "product_model" : "Red", "product_category" : "Chocolate" }, { "customerName" : "M.M. DRUK SERWIS SPÓ?KA Z OGRANICZON? ODPOWIEDZIALNO?CI?", "customerAge" : 4, "count" : "100", "timestamp" : "2020.10.13.10.29.52", "product_brand" : "Milka", "product_model" : "Lapte", "product_category" : "Chocolate" } ]

I would like to have the same output but to copy the fields from the root element( customerName, etc) with one wildcard without specifying each one, is this possible?