| name | using-jq |
| description | jq command-line JSON processor expertise covering filter syntax, object/array
manipulation, data transformation, and CLI tool integration patterns.
Use when processing JSON output from CLI tools (jira, gh, curl), extracting
fields from API responses, transforming JSON data structures, or formatting
JSON for shell consumption. Also use for jq filters, JSON parsing in bash,
or when piping JSON through command-line tools.
|
Using jq
Expert guidance for processing JSON on the command line with jq.
Quick Start
For immediate help, identify your task type and consult the relevant reference:
| Working On | Reference File | Key Topics |
|---|
| Filter syntax, arrays, objects | core-filters | Access, select, map, conditionals, built-ins |
| Jira CLI, GitHub CLI, curl | cli-integrations | Tool-specific JSON patterns |
| Shell variables, TSV, CSV | output-formatting | -r, @tsv, @csv, null handling |
Core Principles
Use -e for Error Detection
Always use jq -e when checking for values — it sets exit code 1 when the result is false or null, enabling proper error handling in shell pipelines.
Use -r for Shell Consumption
Always use jq -r when the output feeds into shell variables, pipes, or further processing. Without -r, strings include surrounding quotes.
Build Filters Incrementally with Pipe
Compose complex filters by chaining simple ones with |:
jq '.items'
jq '.items[]'
jq '.items[] | .name'
Inject Variables with --arg
Never interpolate shell variables into jq filter strings. Use --arg and --argjson:
jq --arg name "$user" '.users[] | select(.name == $name)' data.json
jq --argjson id "$numeric_id" '.items[] | select(.id == $id)' data.json
jq ".users[] | select(.name == \"$user\")" data.json
Common Pattern Template
The canonical pipeline pattern for extracting data from a command:
command_producing_json | jq -r '.path.to.field'
For multiple fields per record:
command_producing_json | jq -r '.items[] | [.field1, .field2] | @tsv'
Anti-Patterns
String Interpolation in Filters
jq ".users[] | select(.name == \"$name\")" file.json
jq --arg name "$name" '.users[] | select(.name == $name)' file.json
Using grep/sed on JSON
curl -s "$url" | grep '"name"' | sed 's/.*: "//;s/".*//'
curl -s "$url" | jq -r '.name'
Unquoted jq Output in Shell
name=$(curl -s "$url" | jq '.name')
name="$(curl -s "$url" | jq -r '.name')"
Ignoring Null Values
jq -r '.optional_field'
jq -r '.optional_field // empty'
jq -r '.optional_field // "default"'
Reference File IDs
For programmatic access: core-filters · cli-integrations · output-formatting