JSON wrangling with jq
Help 2 / 10
Filter data

Select Elements

I’m going to use jq to filter the data returned by the GitHub repository API. The data I get back by default looks like this:

curl "https://api.github.com/repos/stedolan/jq" > repo.json; cat repo.json

jq lets us treat the JSON document as an object and select elements inside of it.

Here is how I filter the JSON document to select the value of the name key:

jq '.name' repo.json

Similarly, for selecting the value of the owner key:

jq '.owner' repo.json

You can drill in as far as you want like this:

jq '.owner.login' repo.json
Loading...