jq cheat sheet

The everyday jq filters at a glance, all against the team document. Press ▶ to run one.

The document the examples run on
{
  "team": "Platform",
  "office": { "city": "Berlin", "floor": 3 },
  "members": [
    { "name": "Ada", "age": 36, "role": "lead", "active": true,
      "email": "[email protected]", "skills": ["rust", "sql"] },
    { "name": "Linus", "age": 28, "role": "dev", "active": true,
      "email": null, "skills": ["c", "shell"] },
    { "name": "Grace", "age": 45, "role": "dev", "active": false,
      "skills": ["cobol"] },
    { "name": "Alan", "age": 41, "role": "qa", "active": true,
      "email": "[email protected]", "skills": [] }
  ]
}
QueryWhat it doesRun it
.teama fieldTry it
.office.citynested fieldsTry it
.members[0]an array element (negative indexes count from the end)Try it
.members[1:3]a slice (the end is exclusive)Try it
.members[]every element, as a streamTry it
.members[] | .namepipe: feed each output into the next filterTry it
[.members[].age]collect a stream into an arrayTry it
.members[] | select(.age > 30)keep only what matchesTry it
.members | map(.age + 1)transform every elementTry it
.members[] | {name, age}build a new objectTry it
.members[] | .email // "n/a"a default for null or missing valuesTry it
.members | lengthcountTry it
.members | map(.age) | add / lengthaverageTry it
.members | sort_by(.age)sortTry it
.members | group_by(.role)groupTry it
.members | map(.skills) | flatten | uniqueflatten and de-duplicateTry it
.members[] | [.name, .age] | @csvone CSV row per member (@tsv for tabs)Try it
.members | INDEX(.name)a lookup table keyed by nameTry it
.members[] | select(.role | IN("dev", "qa"))keep when the value is one of severalTry it
.office | keysan object's keysTry it
.office | tostreamthe value as [path, value] eventsTry it
[.. | numbers]every number anywhere in the documentTry it
"\(.team) HQ"string interpolationTry it

All jq lessons

About jsonquery

Query, format and learn JSON with jq, JSONPath, JMESPath and JSON Pointer. It is the engine of the desktop app, run in your browser.

Engine
The desktop app’s, compiled to WebAssembly
Licence
MIT (the engine and the app)
Source
GitHub
Contact
The contact form (private)
Public issues
GitHub
Legal
Privacy policy

Known limitations: a file over 10 MB opens read-only and one over 512 MB does not open here; the desktop app has no such limit.