jq - How to filter a json that does not contain

Gavriel Fishel picture Gavriel Fishel · Mar 12, 2017 · Viewed 22.3k times · Source

I have an aws query that I want to filter in jq. I want to filter all the imageTags that don't end with "latest"

So far I did this but it filters things containing "latest" while I want to filter things not containing "latest" (or not ending with "latest")

aws ecr describe-images --repository-name <repo> --output json | jq '.[]' | jq '.[]' | jq "select ((.imagePushedAt < 14893094695) and (.imageTags[] | contains(\"latest\")))"

Thanks

Answer

J. Doe picture J. Doe · Mar 12, 2017

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.