jq
17 commands
17 shown
Pretty print JSON
Format and colorize a JSON file
cat data.json | jq '.'
Filter by field
Select objects where a field equals a value
cat data.json | jq '.items[] | select(.status == "Running")'
Extract specific fields
Project only specific fields into a new array
cat data.json | jq '[.items[] | {name:.metadata.name, ns:.metadata.namespace}]'
Group by field
Aggregate items by a field value
cat data.json | jq 'group_by(.namespace) | map({ns: .[0].namespace, count: length})'
Delete a field
Remove a field from JSON output
cat data.json | jq 'del(.metadata.managedFields)'
Convert array to lines
Raw output (-r) for scripting; one value per line
cat data.json | jq -r '.items[].metadata.name'
Merge two JSON objects
Deep-merge two JSON files (override wins)
jq -s '.[0] * .[1]' base.json override.json
Select non-null fields
Filter array elements where value is not null
jq '[.[] | select(.value != null)]' data.json
Group by field
Count records grouped by status field
jq 'group_by(.status) | map({status: .[0].status, count: length})' data.json
Flatten nested array
Flatten one level of nested arrays
jq 'flatten(1)' nested.json
Convert array to object (index_by)
Build an object keyed by the id field
jq 'INDEX(.[]; .id)' items.json
Merge two objects
Deep merge two JSON objects (right wins on conflicts)
jq -s '.[0] * .[1]' base.json override.json
Extract nested value safely
Optional chaining with fallback default value
jq '.config?.database?.host // "localhost"' config.json
Sort by numeric field
Get 5 most recent events sorted by timestamp descending
jq 'sort_by(.timestamp) | reverse | .[0:5]' events.json
Convert JSON to CSV
Output selected fields as comma-separated values
jq -r '.[] | [.id, .name, .status] | @csv' data.json
Add field to every element
Inject a new key-value pair into every array element
jq '[.[] | . + {"env": "prod"}]' items.json
Walk and transform all strings
Recursively lowercase all string values in a JSON document
jq 'walk(if type == "string" then ascii_downcase else . end)' data.json
no commands match