jq is awk for JSON — a command-line processor that filters, transforms, and reshapes JSON using short filter expressions. This cheat sheet collects the 30+ patterns you will actually type, grouped by task. Bookmark it.
Install jq
# macOS
brew install jq
# Ubuntu / Debian
sudo apt install jq
# Windows
winget install jqlang.jqVerify with jq --version. The binary is self-contained with no runtime dependencies.
The basics: access & output
# Pretty-print the whole document (identity filter)
jq '.' file.json
# Raw output — no quotes around strings
jq -r '.name' file.json
# Compact (minified) output
jq -c '.' file.jsonField selection
# Single field
jq '.name' file.json
# Nested field
jq '.user.email' file.json
# Multiple fields into a new object
jq '{name, id}' file.json
# Rename keys
jq '{fullName: .name, userId: .id}' file.jsonWorking with arrays
# Iterate every element (produces multiple outputs)
jq '.[]' file.json
# Get one field from every object
jq '.users[].name' file.json
# Collect results back into an array
jq '[.users[].name]' file.json
# Array length
jq '.items | length' file.json
# First / last element
jq '.items[0]' file.json
jq '.items[-1]' file.json
# Slice
jq '.items[2:5]' file.jsonFiltering with select()
# Keep objects matching a condition
jq '.users[] | select(.age > 30)' file.json
# Match a string value
jq '.users[] | select(.role == "admin")' file.json
# Combine conditions
jq '.users[] | select(.age > 25 and .active == true)' file.json
# Only objects where a field exists
jq '.users[] | select(.email != null)' file.jsonNo terminal? Format & explore JSON in your browser
Paste any JSON and pretty-print, validate, and explore it visually — a zero-install alternative to jq for quick checks. Free and private.
Transforming: map, sort, group
# Transform every element
jq '[.users[] | {name, price}]' file.json
# Sort by a field
jq 'sort_by(.created_at)' file.json
# Group by a field
jq 'group_by(.status)' file.json
# Unique values
jq '[.users[].country] | unique' file.json
# Sum a field
jq '[.orders[].total] | add' file.jsonObject helpers
# All keys of an object
jq 'keys' file.json
# All values
jq 'values' file.json
# Check if a key exists
jq 'has("email")' file.json
# Delete a key
jq 'del(.password)' file.jsonReal-world one-liners
# Pretty-print an API response
curl -s https://api.example.com/users | jq
# Extract one field as raw text (great for shell variables)
TOKEN=$(jq -r '.token' auth.json)
# kubectl: names of pods NOT running
kubectl get pods -o json | jq -r \
'.items[] | select(.status.phase != "Running") | .metadata.name'
# AWS: all S3 bucket names
aws s3api list-buckets | jq -r '.Buckets[].Name'
# Convert array of objects to TSV
jq -r '.users[] | [.name, .email] | @tsv' file.jsonOutput format flags
-r— raw strings, no JSON quotes (use when capturing into shell variables)-c— compact, one JSON value per line (NDJSON)-s— slurp all inputs into a single array-n— null input, for synthesizing JSON@csv,@tsv,@base64— built-in formatters
jq vs JSONPath vs a GUI
Reach for jq when the task lives inside a shell pipeline. For quick visual exploration without the terminal, a browser-based formatter is faster. For path-style extraction in application code, JSONPath is often cleaner.