Select Objects From A List With Jq

Published on May 30, 2022 | Tags: jq JSON dev tools TIL

JQ has a lot of features. Given a JSON, it is possible to select elements from a list from a JSON using the select() function. Example:


$ echo '{"objects": [{"Key": "foo", "Value": "bar"}, {"Key": "baz", "Value": "womp"}]}' | jq '.objects[] | select( .Key == "foo" ) | .Value'
"bar"

And instead of == you can also use the contains() function.


Ferran Jovell