Skip to content

Instantly share code, notes, and snippets.

@handleman
Forked from ipbastola/jq to filter by value.md
Last active September 15, 2020 15:26
Show Gist options
  • Save handleman/aacdc1330a8e8fbff71546d5c03d1e00 to your computer and use it in GitHub Desktop.
Save handleman/aacdc1330a8e8fbff71546d5c03d1e00 to your computer and use it in GitHub Desktop.
JQ to filter JSON by value

JQ to filter JSON by value and produce new json file with filtered data

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

Example: To get json record having _id equal 611

cat my.json | jq -c '[.[] | select( ._id | contains(611))]' > ./myProject/jsons/filtered.json

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment