Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
JQ handy helpers

JQ handy helpers


Testing them

find json online:

This repo > click on a JSON > view Raw and curl the url. ex:


More complex ones:

Contentful example apps:

curl '' -H 'Accept: application/json, text/plain, */*' -H 'Referer: http://localhost:8080/equipe' -H 'Origin: http://localhost:8080' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36' -H 'Authorization: Bearer 0e3ec801b5af550c8a1257e8623b1c77ac9b3d8fcfc1b2b7494e3cb77878f92a'

Pipe it

curl | jq

Cheat sheet



Get specific value in the json

jq '.pets[2].name'

get values using array iterator in the json

jq '.pets[].name'

select only following a specific condition

jq '.pets[] | select(.species=="Dog")'

Restructure json

jq '.pets[] | {title: .name, photoUrl: .photo}'

List all attributes

jq '[path(..)|map(if type=="number" then "[]" else tostring end)|join(".")|split(".[]")|join("[]")]|unique|map("."+.)|.[]'




Trying it live

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.