Pretty-print the entire JSON document
jq '.' data.jsonPractical jq recipes for reading, filtering, reshaping, aggregating and converting JSON from APIs and logs.
Pretty-print the entire JSON document
jq '.' data.jsonRead a field from a nested object
jq '.user.name' data.jsonRead a field from the first array element
jq '.items[0].id' data.jsonExpand an array into separate outputs
jq '.items[]' data.jsonFall back to a default when the field is missing or null
jq '.user.name // "unknown"' data.jsonKeep only elements matching a condition
jq '.[] | select(.age > 18)' users.jsonMap each element to a single field
jq 'map(.name)' users.jsonCount elements matching a condition
jq '[.[] | select(.active)] | length' users.jsonFilter elements then project one field
jq '.[] | select(.role == "admin") | .email' users.jsonKeep elements whose array field contains a value
jq '.[] | select(.tags | index("vue"))' posts.jsonBuild a new object with selected fields
jq '{name: .user.name, city: .user.city}' data.jsonRemove sensitive fields from the output
jq 'del(.password, .token)' user.jsonReshape array elements with shorthand field picks
jq '.items | map({id, price})' data.jsonMerge extra fields into an object
jq '. + {env: "prod"}' data.jsonFilter object fields by key name
jq 'to_entries | map(select(.key != "password")) | from_entries' user.jsonSort elements by a field in ascending order
jq 'sort_by(.price)' products.jsonSort by a numeric field in descending order
jq 'sort_by(-.price)' products.jsonGroup elements by a field and count members
jq 'group_by(.category) | map({category: .[0].category, count: length})' products.jsonSum a numeric field across all elements
jq '[.[].price] | add' products.jsonDeduplicate by a field, keeping the first occurrence
jq 'unique_by(.email)' users.jsonDrop string quotes for shell-friendly output
jq -r '.items[].name' data.json-r affects strings only; numbers are printed unquoted anyway
Compact output on one line for logs and pipes
jq -c '.' data.jsonEmit CSV rows ready for spreadsheets
jq -r '.[] | [.id, .name] | @csv' users.jsonEmit tab-separated rows
jq -r '.[] | [.id, .name] | @tsv' users.jsonPass a shell variable into the jq filter
jq --arg env "prod" '.env = $env' data.jsonMerge multiple JSON arrays into one
jq -s 'add' a.json b.json-s slurps all inputs into a single array
Filter error lines out of a JSONL log
jq -c 'select(.level == "error")' app.logEach line must be a complete JSON value
Generate JSON from a shell variable and the current time
jq -n --arg v "$(git rev-parse --short HEAD)" '{"version": $v, "builtAt": (now | todate)}' > meta.jsonRecursively collect id fields anywhere in the tree
jq '.. | objects | select(has("id")) | .id' data.jsonFlatten nested JSON into dot-separated keys
jq 'reduce paths(scalars) as $p ({}; .[($p | join("."))] = getpath($p))' data.jsonThis website uses cookies to ensure you get the best experience on our website. Privacy Policy.