jq Cheatsheet

Full manual → Click on a row to run the example
Basic Filters
.Identity
.fooGet field
.foo.barNested access
.[0]Array index
.[]Iterate elements
.[]?Iterate, suppress errors
.[2:4]Array slice
| ,Pipe, multiple outputs
. as $xVariable binding
Types & Values
[...]Construct array
{foo, bar}Construct object
..Recursive descent
typeType of value
nullNull value
Operators
+Add/concat/merge
-Subtract/array diff
*Multiply
/Divide/split string
%Modulo
//Fallback alternative
Conditionals & Logic
if-then-elseConditional
== !=Equality
< <= > >=Comparison
and or notBoolean logic
try-catchError handling
?Suppress errors
Transformations
map(f)Transform array
map_values(f)Transform object values
select(cond)Filter elements
del(.foo)Delete key/path
to_entriesObject to key-value array
from_entriesKey-value array to object
pathsAll paths in value
pick(.a, .b)Select paths
Arrays
sortSort ascending
sort_by(.x)Sort by field
uniqueDeduplicate
group_by(.x)Group by field
reverseReverse array
min / maxMin/max element
first / lastFirst/last element
nth(n)Nth element
contains(x)Contains element
indices(x)All indices of x
Strings
split(sep)Split string
join(", ")Join array to string
ascii_downcaseLowercase ASCII
ascii_upcaseUppercase ASCII
ltrimstrTrim prefix
rtrimstrTrim suffix
startswithHas prefix
endswithHas suffix
"\(exp)"String interpolation
test("^a")Regex match
Functions
lengthLength/size
keysObject keys as array
has(key)Key/index exists
in(obj)Key in object
addSum/concat all
any / allAny/all true
flattenFlatten nested arrays
range(3)Numeric range
Advanced
reduce .[] as $x (0; .+$x)Fold/reduce
recurse(f)Recursive apply
walk(f)Recursive transform
while(cond; f)Loop while true
until(cond; f)Loop until true
$ENVEnvironment vars
nowUnix timestamp
tojsonTo JSON string
fromjsonParse JSON string
@base64Base64 encode
@uriURI encode