Extract nested value safely jq
Optional chaining with fallback default value
jq '.config?.database?.host // "localhost"' config.json
more jq
all 17 commands →
Sort by numeric field
jq 'sort_by(.timestamp) | reverse | .[0:5]' events.json
Convert JSON to CSV
jq -r '.[] | [.id, .name, .status] | @csv' data.json
Add field to every element
jq '[.[] | . + {"env": "prod"}]' items.json
Walk and transform all strings
jq 'walk(if type == "string" then ascii_downcase else . end)' data.json
Pretty print JSON
cat data.json | jq '.'