| name | jq |
| description | jq JSON processing - filters, transformations, and queries |
| argument-hint | [query or question] |
| allowed-tools | Bash, Read |
Help with jq based on $ARGUMENTS.
Basic Syntax
cat file.json | jq '.'
jq '.name' file.json
jq '.user.email' file.json
jq '.[0]' file.json
jq '.items[0]' file.json
Filters
jq '{name: .name, email: .email}' file.json
jq '.[]' file.json
jq '.items[]' file.json
jq '.items | map(.name)' file.json
jq '.items | map(select(.active == true))' file.json
jq '.items[] | select(.age > 21)' file.json
Operators
jq '.items | length' file.json
jq '.maybe?.nested?' file.json
jq '.value // "default"' file.json
jq '.price * .quantity' file.json
Constructing Output
jq '{id: .id, full_name: "\(.first) \(.last)"}' file.json
jq '[.items[].name]' file.json
jq '. + {new_field: "value"}' file.json
Common Patterns
jq 'keys' file.json
jq '.items | length' file.json
jq '[.items[].category] | unique' file.json
jq 'group_by(.category)' file.json
jq 'sort_by(.name)' file.json
jq 'flatten' file.json
jq -r '.items[] | [.name, .email] | @csv' file.json
jq -r '.name' file.json
Useful Flags
| Flag | Purpose |
|---|
-r | Raw output (no quotes) |
-c | Compact output |
-s | Slurp (read all inputs into array) |
-e | Exit non-zero if output is null/false |
--arg name val | Pass string variable |
--argjson name val | Pass JSON variable |