~/cstml/documents/cheatsheets/jq
Json tool.
Basic Syntax
Filters
- .
- Identity filter (output input unchanged)
- .foo
- Output value of key "foo"
- .foo.bar
- Output value of "bar" nested within "foo"
- .[0]
- Output first element of array
- .[]
- Output all elements of array
- .[2:4]
- Output array slice (elements 2 through 3)
Object Operations
- .foo?
- Optional object identifier (no error if missing)
- .["foo"]
- Key access (string literal)
- del(.foo)
- Delete key "foo"
- .foo += 1
- Increment value
- .foo = "bar"
- Set value
Array Operations
Basic Array Filters
- length
- Output length of array
- map(.)
- Apply filter to each element
- map(.foo)
- Extract "foo" from each element
- mapvalues(.)
- Like map but for objects
- select(. > 5)
- Keep elements matching predicate
- length
- Output length of array
- map(.)
- Apply filter to each element
- map(.foo)
- Extract "foo" from each element
- mapvalues(.)
- Like map but for objects
- select(. > 5)
- Keep elements matching predicate