jq - How to filter a json that does not contain

Solution 1:

You can use not to reverse the logic

(.imageTags[] | contains(\"latest\") | not)

Also, I'd imagine you can simplify your pipeline into a single jq call.

Solution 2:

In this case contains() doesn't work properly, is better use the not of index() function

select(.imageTags | index("latest") | not)

Solution 3:

All you have to do is | not within your jq

A useful example, in particular for mac brew users:

List all bottled formulae

by querying the JSON and parsing the output

brew info --json=v1 --installed | jq -r "map(select(.installed[].poured_from_bottle) | .name) | unique | .[]" | tr '\n' ' '

List all non-bottled formulae

by querying the JSON and parsing the output and using | not

brew info --json=v1 --installed | jq -r "map(select(.installed[].poured_from_bottle | not) | .name) | unique | .[]"