The syntax
A JSON array is an ordered list of values, wrapped in [], comma-separated, with no restriction on the number of elements:
["a", "b", "c"]
[1, 2, 3]
[{"id": 1}, {"id": 2}]
Arrays don't need uniform types
Unlike a strongly-typed language's array, JSON arrays can freely mix types in one array — this is syntactically valid:
["text", 42, true, null, {"nested": "object"}, [1, 2]]
Whether mixing types is a good idea depends entirely on what's consuming the data — an API contract expecting a uniform array of objects will likely break if a string sneaks in, even though the JSON itself parses fine. The format permits it; your schema or application logic is what should enforce consistency.
No sparse arrays
Some languages support "sparse" arrays with gaps (e.g., an array where index 5 is set but indices 0–4 were never assigned). JSON has no such concept — every element between the opening [ and closing ] must have an explicit value; null is the only way to represent an intentionally empty slot: [1, null, 3].
Order is guaranteed, unlike object keys
Unlike JSON object keys (where order isn't spec-guaranteed), array element order is part of the array's actual meaning and is preserved by every conforming parser — this is exactly why arrays, not objects, are the right structure whenever sequence matters.
Common mistakes
- Assuming array elements must share a type. JSON permits mixed-type arrays; if your application needs uniformity, that's a validation concern (see JSON Schema Tutorial), not something the format itself enforces.
- Confusing an empty array
[]withnull. They mean different things — an empty list versus the explicit absence of a value — and code that treats them interchangeably can hide bugs. - Trying to represent sparse/gapped data directly. Use explicit
nullplaceholders, or restructure as an object keyed by index/ID if gaps are meaningful.
FAQ
Can a JSON array contain different types of elements?
Yes — JSON's grammar doesn't restrict array element types; whether that's appropriate depends on what the array represents.
Is JSON array order guaranteed to be preserved?
Yes — unlike object key order, array element order is part of the array's defined meaning and every conforming parser preserves it.
How do I represent a missing value in a JSON array?
Use null explicitly at that position — JSON has no native concept of sparse or gapped arrays.
Explore and validate nested arrays with the JSON Toolkit — entirely client-side.