snippetTip
jq cheatsheet — common JSON processing patterns
Viewed 0 times
jqJSON processingselectfiltercurl jqcommand line JSON
terminallinuxmacos
Problem
Need to extract, filter, transform JSON data from the command line.
Solution
Essential jq: Select: .field. Nested: .a.b.c. Array: .[0]. All: .[] | .name. Filter: select(.age > 18). Map: [.[] | {name, id}]. Keys: keys. Length: length. Sort: sort_by(.field). Raw strings: -r flag. With curl: curl -s url | jq '.data[]'.
Why
jq is the standard tool for JSON in shell pipelines. Faster than python -c for quick extractions, more readable than grep/sed for structured data.
Revisions (0)
No revisions yet.