JSONATA: Merging Array of objects properties to one object,
This can be applicable only when all properties are unique in objects,
in below example we made Output properties has unique keys
https://try.jsonata.org/aPTBeXmoj
[
{
"TotalVehicles": 181,
"VehicleStatus": "UnReachable",
"count": 90
},
{
"TotalVehicles": 181,
"VehicleStatus": "Stopped",
"count": 87
},
{
"TotalVehicles": 181,
"VehicleStatus": "Running",
"count": 3
},
{
"TotalVehicles": 181,
"VehicleStatus": "Idle",
"count": 1
}
]
CODE:$merge($${ VehicleStatus:{
(VehicleStatus)[0]&"count":count,
"TotalVehicles":TotalVehicles
}}.*)
OP:{
"UnReachablecount": 90,
"TotalVehicles": 181,
"Stoppedcount": 87,
"Runningcount": 3,
"Idlecount": 1
}
No comments:
Post a Comment