JSON Arrays

JSON arrays are ordered sequences of values — unlike objects, order is part of the guarantee. Learn how mixed-type arrays work and when to use an array instead of an object.

Try It Now

Put this into practice with OpenFormatter's free tools — no signup, 100% client-side.

gavel

Specification: RFC 8259 explicitly permits mixed-type arrays: "There is no requirement that the values in an array be of the same type." An array can freely hold strings, numbers, objects, other arrays, and null side by side in one structure.

priority_high

Important: Don't reach for an array with numeric-string keys ("0", "1", "2") pretending to be an object when you actually want an ordered list — that's exactly what a real array is for, and it comes with an actual ordering guarantee an object never makes. Use an object when you're modeling named fields, an array when you're modeling a sequence.

Definition

A JSON array is an ordered sequence of values enclosed in square brackets. This is the one guarantee that sets arrays apart from objects: where RFC 8259 explicitly leaves object member ordering unspecified, array element order is part of the structure itself — the third element is always the third element, for every conforming parser.

JSON itself doesn't define indexing — it defines order. Zero-based indexing is a convenience most parsing languages build on top of that ordering guarantee, not something the JSON specification itself describes. An empty array, `[]`, is valid JSON with zero elements, same as an empty object.

Examples

An array of primitives — order is guaranteed.

["json", "yaml", "xml", "csv"]

A mixed-type array — explicitly permitted by RFC 8259, not just tolerated by lenient parsers.

[1, "two", true, null, { "five": 5 }]

An array of objects — the most common shape for a REST API list response.

[
  { "id": 1, "name": "Ada Lovelace" },
  { "id": 2, "name": "Grace Hopper" }
]

Common Mistakes

Simulating an array with an object that has numeric-string keys

Using { "0": "a", "1": "b", "2": "c" } to represent an ordered list gives up the one guarantee JSON actually makes about arrays — RFC 8259 explicitly leaves object member ordering unspecified, so a receiver has no obligation to preserve "0", "1", "2" in that order.

Fix: Use a real array: ["a", "b", "c"]. If you need an ordered sequence, an array is the JSON structure that guarantees it — an object never does.

Official Specification

Related References