Skip to content

jq command

Read, filter and reshape JSON on the command line.

On this page

Syntax

jq [options] filter [file…]

Provided by the jq package. Run man jq for the full manual.

Common options

OptionWhat it does
.The whole input, pretty-printed
.keyA field
.[]Every array element
-rRaw strings without quotes
-cCompact output, one line
select(COND)Keep items that match
-sRead all inputs into one array
--arg NAME VALPass a variable

Examples

  1. Pretty-print JSON

    jq . data.json
  2. Get a field

    jq .name package.json
  3. Raw string without quotes

    jq -r .version package.json
  4. Every element of an array

    jq '.[]' items.json
  5. One field from each element

    jq -r '.[].name' users.json
  6. Filter items

    jq '.[] | select(.age > 30)' users.json
  7. Count items

    jq length items.json
  8. From an API

    curl -s https://api.github.com/repos/jqlang/jq | jq '.stargazers_count'
  9. Build new objects

    jq '.[] | {id, email}' users.json

jq guides

← All Linux commands · Suggest a fix

Back to top