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
.teamA top-level field →"Platform".,The comma runs each filter on the same input and emits every result, one after another..office.cityChained fields:cityinsideoffice→"Berlin"..nopeA key that doesn't exist givesnull, not an error.
Result
"Platform" "Berlin" null
Example 2Keys that aren't plain identifiers
Document
{ "first name": "Ada L.", "a-b": 1 }Query
.["first name"], ."a-b"
.["first name"]Bracket form: any string works as a key, including ones with spaces.."a-b"Quoted form after the dot: keys containing-or other symbols.
Result
"Ada L." 1
Good to know
.office.cityis just.office | .city— chained fields are two filters joined by a pipe.