Search code examples
jsonselectbooleanjq

jq select condition with nested field


I have the following json string below which I would like to select the proxied field.

I've used: .result[] | select(.proxied=="false") but that results in "no output"

It seems to be how the field proxied is nested and I'm struggling with the jq syntax with the nesting.

Any help would be appreciated.

  "result": [
    {
      "id": "9360f71569e5072910db9cd35ddae",
      "zone_id": "f658530765920e58bcc3a18fbefc38",
      "zone_name": "123.com",
      "name": "123.com",
      "type": "A",
      "content": "123.22.22.221",
      "proxiable": true,
      "proxied": true,
      "ttl": 1,
      "meta": {
        "auto_added": false,
        "managed_by_apps": false,
        "managed_by_argo_tunnel": false
      },
      "comment": null,
      "tags": [],
      "created_on": "2017-10-17T21:58:51.696247Z",
      "modified_on": "2017-10-17T21:58:51.696247Z"
    },
    {
      "id": "e669bde5f1b4879d49d2147c5b8a0",
      "zone_id": "f658530765920a9bcc3a18fbefc38",
      "zone_name": "1234.com",
      "name": "www.1234.com",
      "type": "A",
      "content": "123.202.202.105",
      "proxiable": true,
      "proxied": false,
      "ttl": 1,
      "meta": {
        "auto_added": false,
        "managed_by_apps": false,
        "managed_by_argo_tunnel": false
      },
      "comment": null,
      "tags": [],
      "created_on": "2017-10-17T21:58:51.715343Z",
      "modified_on": "2017-10-17T21:58:51.715343Z"
    }
  ],
  "success": true,
  "errors": [],
  "messages": [],
  "result_info": {
    "page": 1,
    "per_page": 100,
    "count": 2,
    "total_count": 2,
    "total_pages": 1
  }
}

Solution

  • select(.proxied == "false") checks for the string "false", i.e. containing the characters f, a, l, s, and e.

    Instead, use the boolean value false (without quotes):

    .result[] | select(.proxied == false)
    

    Demo

    Or the not operator:

    .result[] | select(.proxied | not)
    

    Demo