JSON ПУТЬ ЗАПРОС - PullRequest
       11

JSON ПУТЬ ЗАПРОС

0 голосов
/ 26 апреля 2020

Я пытаюсь получить значение "id" из этого JSON, используя JSON QUERY. Я пробовал ниже запрос, но он дает вывод как response_body, но я ищу, чтобы получить значение id из тела ответа.

QUERY : $.output.response.response_body

{
  "output": {
    "activity_status": "Success",
    "response": {
      "elapsed_time": 0.585922725,
      "end_time": "2020-04-25T02:26:17.536980266Z",
      "response_body": "{\"id\":14,\"type\":\"host\",\"url\":\"/api/v2/hosts/14/\",\"related\":{\"named_url\":\"/api/v2/hosts/99.79.195.123++import++Default/\",\"created_by\":\"/api/v2/users/1/\",\"modified_by\":\"/api/v2/users/1/\",\"variable_data\":\"/api/v2/hosts/14/variable_data/\",\"groups\":\"/api/v2/hosts/14/groups/\",\"all_groups\":\"/api/v2/hosts/14/all_groups/\",\"job_events\":\"/api/v2/hosts/14/job_events/\",\"job_host_summaries\":\"/api/v2/hosts/14/job_host_summaries/\",\"activity_stream\":\"/api/v2/hosts/14/activity_stream/\",\"inventory_sources\":\"/api/v2/hosts/14/inventory_sources/\",\"smart_inventories\":\"/api/v2/hosts/14/smart_inventories/\",\"ad_hoc_commands\":\"/api/v2/hosts/14/ad_hoc_commands/\",\"ad_hoc_command_events\":\"/api/v2/hosts/14/ad_hoc_command_events/\",\"insights\":\"/api/v2/hosts/14/insights/\",\"ansible_facts\":\"/api/v2/hosts/14/ansible_facts/\",\"inventory\":\"/api/v2/inventories/4/\"},\"summary_fields\":{\"inventory\":{\"id\":4,\"name\":\"import\",\"description\":\"\",\"has_active_failures\":false,\"total_hosts\":1,\"hosts_with_active_failures\":0,\"total_groups\":0,\"groups_with_active_failures\":0,\"has_inventory_sources\":false,\"total_inventory_sources\":0,\"inventory_sources_with_failures\":0,\"organization_id\":1,\"kind\":\"\"},\"created_by\":{\"id\":1,\"username\":\"admin\",\"first_name\":\"\",\"last_name\":\"\"},\"modified_by\":{\"id\":1,\"username\":\"admin\",\"first_name\":\"\",\"last_name\":\"\"},\"user_capabilities\":{\"edit\":true,\"delete\":true},\"groups\":{\"count\":0,\"results\":[]},\"recent_jobs\":[]},\"created\":\"2020-04-25T02:26:17.469867Z\",\"modified\":\"2020-04-25T02:26:17.469884Z\",\"name\":\"99.79.195.123\",\"description\":\"\",\"inventory\":4,\"enabled\":true,\"instance_id\":\"\",\"variables\":\"\",\"has_active_failures\":false,\"has_inventory_sources\":false,\"last_job\":null,\"last_job_host_summary\":null,\"insights_system_id\":null,\"ansible_facts_modified\":null}",
      "response_headers": [
        {
          "name": "Expires",
          "value": "0"
        },
        {
          "name": "Content-Language",
          "value": "en"
        },
        {
          "name": "Allow",
          "value": "GET, POST, HEAD, OPTIONS"
        }
      ],
      "start_time": "2020-04-25T02:26:16.951057541Z",
      "status_code": 201,
      "status_text": "201 Created",
      "succeeded": true
    }
  }
}
QUERY : $.response_body[?(@.'id')].response

OUTPUT : [
    "{\"id\":14,\"type\":\"host\",\"url\":\"/api/v2/hosts/14/\",\"related\":{\"named_url\":\"/api/v2/hosts/99.79.195.123++import++Default/\",\"created_by\":\"/api/v2/users/1/\",\"modified_by\":\"/api/v2/users/1/\",\"variable_data\":\"/api/v2/hosts/14/variable_data/\",\"groups\":\"/api/v2/hosts/14/groups/\",\"all_groups\":\"/api/v2/hosts/14/all_groups/\",\"job_events\":\"/api/v2/hosts/14/job_events/\",\"job_host_summaries\":\"/api/v2/hosts/14/job_host_summaries/\",\"activity_stream\":\"/api/v2/hosts/14/activity_stream/\",\"inventory_sources\":\"/api/v2/hosts/14/inventory_sources/\",\"smart_inventories\":\"/api/v2/hosts/14/smart_inventories/\",\"ad_hoc_commands\":\"/api/v2/hosts/14/ad_hoc_commands/\",\"ad_hoc_command_events\":\"/api/v2/hosts/14/ad_hoc_command_events/\",\"insights\":\"/api/v2/hosts/14/insights/\",\"ansible_facts\":\"/api/v2/hosts/14/ansible_facts/\",\"inventory\":\"/api/v2/inventories/4/\"},\"summary_fields\":{\"inventory\":{\"id\":4,\"name\":\"import\",\"description\":\"\",\"has_active_failures\":false,\"total_hosts\":1,\"hosts_with_active_failures\":0,\"total_groups\":0,\"groups_with_active_failures\":0,\"has_inventory_sources\":false,\"total_inventory_sources\":0,\"inventory_sources_with_failures\":0,\"organization_id\":1,\"kind\":\"\"},\"created_by\":{\"id\":1,\"username\":\"admin\",\"first_name\":\"\",\"last_name\":\"\"},\"modified_by\":{\"id\":1,\"username\":\"admin\",\"first_name\":\"\",\"last_name\":\"\"},\"user_capabilities\":{\"edit\":true,\"delete\":true},\"groups\":{\"count\":0,\"results\":[]},\"recent_jobs\":[]},\"created\":\"2020-04-25T02:26:17.469867Z\",\"modified\":\"2020-04-25T02:26:17.469884Z\",\"name\":\"99.79.195.123\",\"description\":\"\",\"inventory\":4,\"enabled\":true,\"instance_id\":\"\",\"variables\":\"\",\"has_active_failures\":false,\"has_inventory_sources\":false,\"last_job\":null,\"last_job_host_summary\":null,\"insights_system_id\":null,\"ansible_facts_modified\":null}"
]

Я ожидаю вывод в качестве значения id в теле ответа

{
  "14"
}
...