Skip to content

JSON Selector Filter help

dgtlmoon edited this page Oct 12, 2022 · 15 revisions

JSON (jsonpath) filter json:...

To just indent a response, for better diffs, use json:$.


Some ideas, if you want to select where a value is set to something

[
    {
        "id": "DK*CLE*E11499*1",
        "status": 3,
        "price": null,
        "free": false,
        "link": null
    },
    {
        "id": "DK*CLE*E11499*2",
        "status": 2,
        "price": null,
        "free": false,
        "link": null
    }
]

Try json:$[?(@.status==3)]

"Filter" compatibility with other JSON selector libraries

json:$.address[?(@.use="work")] works

json:$.address.[?(@.use="work")] does not work/validate

see https://github.com/dgtlmoon/changedetection.io/discussions/711

JQ filter (jq:...)

  • The example below adds the price in dollars to each item in the JSON data, and then filters to only show items that are greater than 10.

Sample input data from API

{
    "items": [
        {
           "name": "Product A",
           "priceInCents": 2500
        },
        {
           "name": "Product B",
           "priceInCents": 500
        },
        {
           "name": "Product C",
           "priceInCents": 2000
        }
    ]
}

Sample jq

jq:.items[] | . + { "priceInDollars": (.priceInCents / 100) } | select(.priceInDollars > 10)

Sample output data

{
  "name": "Product A",
  "priceInCents": 2500,
  "priceInDollars": 25
}
{
  "name": "Product C",
  "priceInCents": 2000,
  "priceInDollars": 20
}

Clone this wiki locally