Skip to main content
Ganesh Joshi
Back to Cheatsheets

jq JSON CLI

Updated 2026-02-15

jq for filtering and transforming JSON in the shell. Select fields, slice arrays, and format output.

Select and filter

  • echo '{"a":1}' | jq .a

    Get field.

  • jq '.items[]' file.json

    Array iteration.

  • jq '.users[] | select(.age > 18)' file.json

    Filter objects.

  • jq '.key // "default"' file.json

    Default value.

Transform and build

  • jq -s 'add' file.json

    Slurp and add (e.g. numbers).

  • jq '[.items[].name]' file.json

    Build array of values.

  • jq '{key: .field}' file.json

    Build object.

  • jq -r '.name'

    Raw output (no quotes).

jq JSON CLI | Cheatsheet | Ganesh Joshi