jq · lesson 2 of 32 · Getting started

Nesting & missing keys

Chain fields to walk into nested objects. Asking for a key that doesn't exist is not an error — you get null. A comma runs several filters on the same input and emits every result.

Examples

Example 1Nested fields, a missing key, and the comma

Document

{
  "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": [] }
  ]
}

Query

.team, .office.city, .nope
  1. .team A top-level field → "Platform".
  2. , The comma runs each filter on the same input and emits every result, one after another.
  3. .office.city Chained fields: city inside office → "Berlin".
  4. .nope A key that doesn't exist gives null, not an error.

Result

"Platform"
"Berlin"
null

Try it in the playground

Example 2Keys that aren't plain identifiers

Document

{ "first name": "Ada L.", "a-b": 1 }

Query

.["first name"], ."a-b"
  1. .["first name"] Bracket form: any string works as a key, including ones with spaces.
  2. ."a-b" Quoted form after the dot: keys containing - or other symbols.

Result

"Ada L."
1

Try it in the playground

Good to know

  • .office.city is just .office | .city — chained fields are two filters joined by a pipe.

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.