JSON Objects and Arrays

Patterns for nested objects, arrays, list items, nullability, and common data-shape decisions in JSON.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

Object patterns

Objects model named fields and records.

Simple object

Use objects for named properties.

jsonANYjsonobject
json
{
  "id": 101,
  "name": "Ada"
}
Notes

Objects are ideal for records with labeled fields.

Nested object

Represent related subfields in a child object.

jsonANYjsonobjectnested
json
{
  "user": {
    "id": 101,
    "profile": {
      "city": "Austin",
      "timezone": "America/Chicago"
    }
  }
}
Notes

Nested objects group related data and reduce flat key sprawl.

Missing property vs null property

Omitting a field is different from setting it to null.

jsonANYjsonobjectnull
json
{
  "nickname": null
}
Notes

A missing property can mean "unknown" or "not sent". `null` usually means explicitly empty.

Array patterns

Arrays model ordered collections of values or objects.

Array of strings

A simple list of primitive values.

jsonANYjsonarraystrings
json
[
  "red",
  "green",
  "blue"
]
Notes

A useful pattern for tags, labels, and simple lists.

Array of objects

A common shape for API collections.

jsonANYjsonarrayobjects
json
[
  { "id": 1, "name": "Ada" },
  { "id": 2, "name": "Linus" }
]
Notes

Widely used for query results and exports.

Mixed-type arrays are legal but risky

JSON allows mixed types, but they are often harder to consume.

jsonANYjsonarraymixed-types
json
[1, "two", true, null]
Notes

Prefer consistent item shapes unless you have a strong reason not to.

Extract a field from each array item

Print one property from every object in an array.

bashANYjsonjqarrays
bash
jq '.[].name' users.json
Notes

Great for inspecting list payloads quickly.

Recommended next

No recommendations yet.