jq flags & options

-r, --raw-output

Output raw strings without JSON quotes.

echo '{"name":"joe"}' | jq -r '.name'

-c, --compact-output

Print output on a single line instead of pretty-printed.

echo '{"a":1,"b":2}' | jq -c '.'

-e, --exit-status

Set exit status based on output: 0 if truthy, 1 if false/null.

echo '{"ok":true}' | jq -e '.ok'

-s, --slurp

Read all inputs into a single array.

cat items.jsonl | jq -s '.'
cat items.jsonl | jq -s 'length'

-n, --null-input

Don't read any input. Useful for constructing JSON from scratch.

jq -n '{"key": "value"}'

--arg

Pass a string value as a variable.

jq --arg name "joe" '.user = $name' data.json

--argjson

Pass a JSON value as a variable.

jq --argjson count 5 '.limit = $count' data.json

.field

Access an object field.

echo '{"name":"joe","age":30}' | jq '.name'

.[]

Iterate over array elements.

echo '[1,2,3]' | jq '.[]'

select()

Filter elements matching a condition.

echo '[{"a":1},{"a":2},{"a":3}]' | jq '.[] | select(.a > 1)'

map()

Apply a transformation to each array element.

echo '[1,2,3]' | jq 'map(. * 2)'

keys, length, type

Inspect JSON structure.

echo '{"a":1,"b":2}' | jq 'keys'
echo '[1,2,3]' | jq 'length'