qntfy / kazaam

Arbitrary transformations of JSON in Golang
MIT License
281 stars 54 forks source link

Transform array from array #84

Open manishs747 opened 6 years ago

manishs747 commented 6 years ago

Specks to transform array to array. array length will be dynamic.

eg:

{ "prices": [ { "name": "Journey Mileage", "type": "BASE", "tax": "V20", "amount": 30, "rate": 2.5, "unit": "miles", "charge": 75 } ] }

output: { "charges": [ { "amount": "2095", "currency": "EUR", "type": "price_base" } ] }

mainpart commented 2 years ago

something like

[
{
operation : shift,
spec: {
field_newname : field_oldname,
field_newname1 : field_oldname1,
},
over: "prices[*]"
},
{
operation: shift
spec:{
output : prices
}
}
]

first section will replace original prices keys with new ones, forming an array of objects with only specified keys (with new key names and values from that old keys). second shift will bring every line mentioned to new top-level json