jq
Filter by value
To filter for values in jq the select
function can be used in combination with contains
. The
contains(arg)
function will return true if the input completely contains the provided argument.
json='[{ "id": "foo" }, { "id": "bar" }, { "id": "baz" }]'
echo $json | jq -c '.[] | select(.id | contains("ba"))'
# {"id":"bar"}
# {"id":"baz"}
Or use ==
when an exact match is required
json='[{ "id": "foo" }, { "id": "bar" }, { "id": "baz" }]'
echo $json | jq -c '.[] | select(.id == "baz")'
# {"id":"baz"}