Jolt transformation with nested arrays. -
i'm trying write spec below transformation using jolt transformation. i'm interested in changing name of key in json, value should remain same. me out.
input json:
[ { "list1": [ { "id": "cpp1600000009846", "list2": [ { "amount": { "formattedprimeamount": "0.00", "primeamount": "0.00" }, "code": "conamp" }, { "amount": { "formattedprimeamount": "0.00", "primeamount": "0.00" }, "code": "pccpri" }, { "amount": { "formattedprimeamount": "0.00", "primeamount": "0.00" }, "code": "pccpci" }, { "amount": { "formattedprimeamount": "0.00", "primeamount": "0.00" }, "code": "pccpii" } ] }, { "id": "cpp1600000009846", "list2": [ { "amount": { "formattedprimeamount": "0.00", "primeamount": "0.00" }, "code": "coneit" }, { "amount": { "formattedprimeamount": "0.00", "primeamount": "0.00" }, "code": "concrt" }, { "amount": { "formattedprimeamount": "0.00", "primeamount": "0.00" }, "code": "connct" } ] } ] } ]
expected output:
[ { "lista": [ { "num": "cpp1600000009846", "listb": [ { "rate": { "formattedprimeamount": "0.00", "primeamount": "0.00" }, "covg_code": "conamp" }, { "rate": { "formattedprimeamount": "0.00", "primeamount": "0.00" }, "covg_code": "pccpri" }, { "rate": { "formattedprimeamount": "0.00", "primeamount": "0.00" }, "covg_code": "pccpci" }, { "rate": { "formattedprimeamount": "0.00", "primeamount": "0.00" }, "covg_code": "pccpii" } ] }, { "num": "cpp1600000009846", "listb": [ { "rate": { "formattedprimeamount": "0.00", "primeamount": "0.00" }, "covg_code": "coneit" }, { "rate": { "formattedprimeamount": "0.00", "primeamount": "0.00" }, "covg_code": "concrt" }, { "rate": { "formattedprimeamount": "0.00", "primeamount": "0.00" }, "covg_code": "connct" } ] } ] } ]
use following spec
[ { "operation": "shift", "spec": { "list1" : { "*": { "id" : "lista[&1].num", "list2" : { "*": { "amount" : "lista[&1].listb[&3].rate", "code" : "lista[&1].listb[&3].covg_code" } } } } } } ]
run spec using following code
list<object> chainrspecjson = jsonutils.filepathtolist( "d:\\path\\to\\spec.json" ); chainr chainr = chainr.fromspec( chainrspecjson ); list<object> inputjsonlist = jsonutils.filepathtolist( "d:\\path\\to\\input.json" ); list<object> outputlist = new arraylist<object>(); for(object singleobj : inputjsonlist){ object transformedoutput = chainr.transform( singleobj ); outputlist.add(transformedoutput); }
Comments
Post a Comment