jq Cheatsheet
jq is a lightweight command-line JSON processor, like sed/awk for JSON data. Supports filtering, mapping, transformation, and aggregation — essential for API debugging and data processing.
Updated: 2026-07-20·20 commands
Quick Start
``bash
jq '.' data.json # Pretty-print
jq '.name' package.json # Extract key
jq '.dependencies | keys' pkg.json # List dependency names
jq '.[] | select(.age > 30)' users.json # Filter array
jq -r '.version' package.json # Raw output (no quotes)
``
Startup & Modes(20)
| Command | Level | ||
|---|---|---|---|
jq --helpShow jq help | Basic | jq --help | |
jq '.' file.jsonPretty-print JSON (format + color) | Basic | jq '.' data.json | |
jq '.key'Extract value of a key | Basic | jq '.name' package.json | |
jq '.a.b.c'Extract nested key (chained access) | Basic | jq '.dependencies.jquery' package.json | |
jq '.[]'Iterate over array elements | Intermediate | jq '.[]' array.json | |
jq '.[0]'Get first array element | Basic | jq '.[0]' array.json | |
jq '.[] | .name'Iterate array and extract each name | Intermediate | curl -s https://api.github.com/repos/jqlang/jq | jq '.owner | {login, id}' | |
jq '. | {key1, key2}'Select fields to construct new object | Intermediate | jq '{name, version}' package.json | |
jq 'select(.age > 30)'Filter array by condition | Intermediate | jq '.[] | select(.age > 30)' users.json | |
jq -rRaw output (no quotes) | Basic | jq -r '.name' package.json | |
jq -cCompact output (one JSON per line) | Basic | jq -c '.[]' data.json | |
jq -fRead jq filter from file | Intermediate | jq -f my-filter.jq data.json | |
jq 'group_by(.key)'Group by specified key | Expert | jq 'group_by(.category)' data.json | |
jq 'sort_by(.key)'Sort by key | Intermediate | jq 'sort_by(.stars) | reverse' repos.json | |
jq 'length'Calculate array length | Basic | jq 'length' array.json | |
jq 'keys'List all object keys | Basic | jq 'keys' package.json | |
jq map selectApply mapping to each array element | Intermediate | jq 'map(select(.version > "1.0"))' deps.json
| |
jq -sRead multiple JSON objects into array (slurp) | Intermediate | jq -s '.' file1.json file2.json | |
jq -nUse null input (test filters) | Intermediate | jq -n '{a: 1, b: 2}' | |
jq 'add'Sum array elements | Intermediate | jq '[.[].price] | add' items.json |
FAQ
This cheatsheet is compiled from official tool documentation. Last updated: 2026-07-20.