-
-
Notifications
You must be signed in to change notification settings - Fork 1k
JSON Selector Filter help
changedetection.io supports processing JSON information in a filter, so you can extract/monitor only the information that's important to you - for example when you just want a notification when a particular part of a JSON feed changes.
This is achieved by using either a json:
or jq:
filter in the "Filter" settings of a watch.
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)]
json:$.address[?(@.use="work")]
works
json:$.address.[?(@.use="work")]
does not work/validate, see https://github.com/dgtlmoon/changedetection.io/discussions/711
'AND' (&&
) operator may not work in JSONPath but will work with other libraries, see https://github.com/dgtlmoon/changedetection.io/issues/1116#issuecomment-1312479052 for a workaround using JQ
For more complex parsing, filtering, and modifying of JSON data, jq is recommended due to the built-in operators and functions. Refer to the documentation for more specifc information on jq.
Notes:
-
jq
must be added manually separately from the installation of changedetection.io (simply runpip3 install jq
) -
jq
is not available on Windows or must be manually compiled (No "wheel" package available on pypi)
One big advantage of jq
is that you can use logic in your JSON filter, such as filters to only show items that have a value greater than/less than etc.
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.
{
"items": [
{
"name": "Product A",
"priceInCents": 2500
},
{
"name": "Product B",
"priceInCents": 500
},
{
"name": "Product C",
"priceInCents": 2000
}
]
}
jq:.items[] | . + { "priceInDollars": (.priceInCents / 100) } | select(.priceInDollars > 10)
{
"name": "Product A",
"priceInCents": 2500,
"priceInDollars": 25
}
{
"name": "Product C",
"priceInCents": 2000,
"priceInDollars": 20
}