Daniel Daniel - 2 months ago 20
JSON Question

Parser uncommon JSON Output in shell script

I need help to parser this JSON Output

Each object brings me a number from 0 to 20, but each host has to parser deploy_status from the host by id number not from the object number because this JSON is very different for me, i am using shell-script I do have jq

"meta": {
"total_count": 21,
"previous": null,
"offset": 0,
"next": null,
"limit": 21
}
}
"objects": [
{
"configuration_id": 61,
"deploy_error": "",
"deploy_progress": 100,
"deploy_status": "deploy_succeeded",
"id": 61,
"last_reported": "2016-09-02T11:41:37",
"last_updated": "2016-09-02T11:21:38",
"maintenance_mode": false,
"max_audio_calls": 99,
"max_full_hd_calls": 4,
"max_hd_calls": 8,
"max_sd_calls": 18,
"media_load": 0,
"name": "host1",
"resource_uri": "/api/admin/status/v1/worker_vm/61/",
"system_location": "Customer-host",
"upgrade_status": "IDLE",
"version": "12 (29682.0.0)"
},
{
"configuration_id": 62,
"deploy_error": "",
"deploy_progress": 100,
"deploy_status": "deploy_succeeded",
"id": 62,
"last_reported": "2016-09-01T16:02:44",
"last_updated": null,
"maintenance_mode": false,
"max_audio_calls": 0,
"max_full_hd_calls": 0,
"max_hd_calls": 0,
"max_sd_calls": 0,
"media_load": 0,
"name": "host3",
"resource_uri": "/api/admin/status/v1/worker_vm/62/",
"system_location": "customer-host",
"upgrade_status": "IDLE",
"version": "11.1 (26965.0.0)"
}
]

Answer

The code below works as a Charm! Thanks Phylogenesis.

jq ".objects" | jq "map(select(.id == $id))" | jq ".[].deploy_status"
Comments