Skip to content
Latchkey

jq Cheat Sheet: Filters, Selectors & Transformations

The jq filters and selectors for slicing JSON in one quick reference.

Select, filter, and reshape JSON on the command line with jq.

Selectors

FilterDoes
.keyField value
.a.b.cNested field
.[]Iterate array/object values
.[0]First element
.key // "x"Default if null
.["weird-key"]Bracket access

Transform

FilterDoes
map(.name)Project a field
select(.age > 18)Keep matching
{name, id}Reshape object
group_by(.type)Group
sort_by(.ts)Sort
lengthCount / string length
keysObject keys

Flags & examples

Terminal
jq -r '.items[].name' data.json     # -r: raw strings
jq '.[] | select(.active)' data.json
jq -n --arg v "$VAL" '{value: $v}'  # build from shell var
curl -s api/x | jq '.data | length'

Key takeaways

  • -r outputs raw strings (no quotes) for shell consumption.
  • select() filters; map() projects across an array.
  • --arg safely injects a shell variable into a jq program.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →