Skip to content

Instantly share code, notes, and snippets.

@ipbastola
Last active April 25, 2024 17:14
Show Gist options
  • Save ipbastola/2c955d8bf2e96f9b1077b15f995bdae3 to your computer and use it in GitHub Desktop.
Save ipbastola/2c955d8bf2e96f9b1077b15f995bdae3 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)

@mikeschinkel
Copy link

@jcallen — Very cool!

And as they say, "I learn something new everyday!" 🙂

@gangsta
Copy link

gangsta commented Oct 15, 2023

If you're looking after - how to parse JSON and select date range
Look at here https://gist.github.com/gangsta/702e071fd048db2e39c7907f40d0cfd4

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