Skip to content

Instantly share code, notes, and snippets.

@examinedliving
Forked from ipbastola/jq to filter by value.md
Last active January 22, 2021 20:41
Show Gist options
  • Save examinedliving/6c810af24823a639927972c1ce007b52 to your computer and use it in GitHub Desktop.
Save examinedliving/6c810af24823a639927972c1ce007b52 to your computer and use it in GitHub Desktop.
JQ to filter JSON by value

JQ to filter JSON by value

Syntax: cat <filename> | jq -c '.[] | select( .<key> | contains("<value>"))'

Example: To get json record having _id equal 611

cat my.json | jq -c '.[] | select( ._id | contains(611))'

Remember: if JSON value has no double quotes (eg. for numeric) to do not supply in filter i.e. in contains(611)

From Command prompt on windows, it's like so: (use more if you don't have cat - or get cat)

cat file.json | jq -C ".[] | select ( .key | contains(\"<value>\"))"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment