Code & computing / QUICK REFERENCE
jq JSON essentials
Select, reshape, filter and summarize JSON with small shell-friendly examples.
Inspect and select
- Pretty-print JSON
jq '.' data.jsonParses input and formats each JSON value. [2]
- Select a property
jq '.name' data.jsonMissing object keys generally produce null. [2]
- Nested property
jq '.user.name' data.jsonInput structure must support the path. [2]
- First array element
jq '.[0]' data.jsonIndexes are zero-based. [2]
- Last array element
jq '.[-1]' data.jsonNegative index counts backward. [2]
- Iterate array values
jq '.[]' data.jsonEmits each element as a separate result. [2]
- Array slice
jq '.[1:4]' data.jsonThe end index is excluded. [2]
- Raw string output
jq -r '.name' data.jsonRemoves JSON string quoting, not arbitrary escaping for a shell. [2]
Filter and reshape
- Project two fields
jq '{name, count}' data.jsonCreates a new object using these keys. [1]
- Rename a field
jq '{label: .name}' data.jsonConstructs a differently named output property. [1]
- Keep matching objects
jq '.[] | select(.active == true)' data.jsonselect emits only values satisfying the test. [1]
- Map an array
jq 'map(.name)' data.jsonReturns an array of each element's name. [1]
- Count elements
jq 'length' data.jsonMeaning depends on the input type. [1]
- List object keys
jq 'keys' data.jsonSorts object keys. [1]
- Sorted objects
jq 'sort_by(.name)' data.jsonExpects an array. [1]
- Deduplicate values
jq 'unique' data.jsonSorts and removes duplicate array values. [1]
Practical composition
- Fallback value
jq '.name // "unknown"' data.json// also uses the fallback for false, not only null. [1]
- Check key presence
jq 'has("name")' data.jsonDistinguishes missing keys from an explicit null value. [1]
- Pass a string safely
jq --arg wanted 'Atlas' '.[] | select(.name == $wanted)' data.json--arg avoids injecting shell text into filter syntax. [1]
- Pass a JSON value
jq --argjson limit 3 '.[:$limit]' data.json--argjson parses its argument as JSON. [1]
- Compact output
jq -c '.' data.jsonEmits compact JSON values. [1]
- Slurp a stream
jq -s '.' data.jsonReads input values into one array; memory use grows with input. [1]
- Create JSON without input
jq -n --arg name 'Atlas' '{name: $name}'Avoids string-concatenating a JSON document. [1]
- Fail on false/null result
jq -e '.active == true' data.jsonExit status depends on the last result; handle empty output too. [1]
Reserved placement, separate from reference controls. No ad network is active.
No matching entry. Try a shorter word or clear the search to see the complete sheet.
Sources
cheatsheetatlas.com/sheets/jq/ · Updated 2026-10-19 · jq · core filters / POSIX shell quoting