I have this input JSON:
{
"stores": {
"1100": {
"metric1": "27",
"metric2": "3013775",
"indicator": 8.96
},
"1200": {
"metric1": "2",
"metric2": "354418",
"indicator": 5.64
}
}
}
And need to transform the value of each store in the value from the child indicator, like that:
{
"stores": {
"1100": 8.96,
"1200": 5.64
}
}
How can I do this?
CodePudding user response:
You can use a shift transformation like this
[
{
"operation": "shift",
"spec": {
"stores": {
"*": {
"indicator": "&2.&1"
}
}
}
}
]
where "*" represents the indices of the stores object. eg we walk through the elements of the stores object as restricting results to the values of the "indicator" key in which &2 represents going two level up and grabbing the key name("stores") and &1 represents going one level up and grabbing the values of the indices("1100","1200")