jq Quick Reference

Slice, filter, and reshape JSON on the command line. Pipe curl into jq and stop eye-parsing giant payloads.

Access

Whole thing, pretty
jq .
A field
jq .name · nested: jq .user.email
Array element
jq '.[0]' · last: jq '.[-1]'
All array elements
jq '.[]' — stream each item
Safe access
jq '.maybe?' — no error if missing

Filter & transform

Pick fields
jq '{name, id}' · rename: jq '{n: .name}'
Map an array
jq 'map(.price)' · or jq '.[].price'
Filter
jq '.[] | select(.age > 30)'
Count / length
jq 'length' · jq 'map(select(.ok)) | length'
Sort / unique
jq 'sort_by(.age)' · jq 'unique'
Keys
jq 'keys' · values: jq '[.[]]'

Output

Raw strings (no quotes)
jq -r .name — pipe into shell safely
To CSV/TSV
jq -r '.[] | [.id, .name] | @csv'
Compact
jq -c . — one line, good for streaming
Build a string
jq -r '"\(.name): \(.age)"'