Cheatsheet: JQ
Basic operations
Identity operator (.)
Object identifier/index
Generic object index
Array operations
Array index
Array/string slice
Array length
Object construction
Select fields without renaming
Select fields with renaming
Concatenate fields
Value as field name
Filtering and transforms
Filter objects by key value
Sort an array by key value
Group by key value (sort first)
Flatten nested arrays
Merge multiple objects with slurp
map/to_entries/from_entries/with_entries
map - transform each array item
map_values - similar to map for object values
to_entries - object to array of key/value pairs
from_entries - key/value pairs to object
with_entries - edit keys/values inline
CLI and safety patterns
Raw output (no JSON quotes)
Fallback/default value
Optional chaining style access
Pass a string argument
Pass a JSON argument
if/else and helper functions
if/else
if/elif/else
Helper functions
See also: