jq Filter Reference

Every jq filter, operator and built-in function with description and examples

Searchable jq reference covering identity, field and index access, pipes, the comma, object/array construction, conditionals, reduce, and the most-used built-in functions like map, select, keys, length and to_entries.

What is the jq identity filter?

The identity filter is a single dot (.) and returns its input unchanged. It is the simplest filter and the starting point of most pipelines — for example, .name reads the name field of the input, where the leading dot is the identity that the field access applies to.

jq is a command-line processor for JSON: you pipe JSON in, apply a filter, and get transformed JSON out. A jq program is a filter — a small expression that takes an input value and produces zero or more output values. Filters compose with the pipe | and the comma ,. This reference lists the operators, constructors and the built-in functions you use most.

How it works

jq reads a stream of JSON values and runs your filter against each one. The most basic filter is . (identity), which returns the input untouched. From there you navigate with .field, .[index] and the iterator .[], transform with map, select, arithmetic and string functions, and assemble results with {} / [] constructors. The pipe | connects stages so each filter’s output becomes the next one’s input.

Worked examples

echo '{"users":[{"name":"A","age":30},{"name":"B","age":15}]}' \
  | jq '.users | map(select(.age >= 18)) | map(.name)'
# => ["A"]

echo '{"a":1,"b":2}' | jq 'to_entries | map(.key)'
# => ["a","b"]

echo '[1,2,3]' | jq 'add'
# => 6

Notes and tips

Wrap an iterating pipeline in [ ... ] to collect a stream back into an array, and use -r on the command line for raw (unquoted) string output. select emits nothing when its condition is false, so it naturally filters streams. Prefer reduce or add for aggregation, and to_entries / from_entries to treat an object as an iterable list of key/value pairs.