Sample input1.json
[{
\"organizationId\": \"org1\",
\"status\": \"UP\",
\"server\": \"server1\"
jq
solution:
jq 'group_by(.organizationId)
| map(reduce .[] as $o ({"Down_Count" : 0};
if $o["status"] == "DOWN" then .Down_Count += 1 else . end
| . + { ($o["server"]) : $o["status"],
"organizationId" : $o["organizationId"] }
))' input.json
The output:
[
{
"Down_Count": 2,
"server1": "UP",
"organizationId": "org1",
"server2": "DOWN",
"server3": "DOWN"
},
{
"Down_Count": 0,
"server1": "UP",
"organizationId": "org2",
"server2": "UP"
}
]