解析器shell脚本

时间:2016-09-02 12:27:01

标签: json linux shell

我需要帮助解析此JSON输出

每个对象给我一个从0到20的数字,但是每个主机必须通过id号从主机解析deploy_status,而不是从对象号解析,因为这个JSON对我来说非常不同,我使用shell脚本我确实有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)"
      }
    ]

1 个答案:

答案 0 :(得分:0)

以下代码充当魅力! 谢谢Phylogenesis。

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