What Is a JSON Array

A JSON array is an ordered list of values, delimited by square brackets []. It’s used to represent a collection of items where order matters and items are accessed by position, not by name.

Basic syntax

// json
["apple", "banana", "orange"]

Values are separated by commas, and the entire array is wrapped in square brackets.

Arrays can contain any type of value

Unlike arrays in some typed languages, a JSON array can mix different types in the same array (though, in practice, it’s more common and more predictable to keep every item the same type).

// json
["text", 42, true, null]

Arrays can contain objects

This is one of the most common patterns day to day, especially in API responses that return a list of records.

// json
[
  { "name": "Ana", "age": 30 },
  { "name": "John", "age": 25 }
]

Arrays can contain other arrays (nesting)

// json
[
  ["a", "b"],
  ["c", "d"]
]

This is common, for example, to represent a matrix or a table.

Arrays can be empty

// json
[]

An empty array is perfectly valid JSON, and often shows up in API responses when a search returns no results.

Accessing items by index

The first item in a JSON array has index 0, following the convention of most programming languages.

// javascript
const fruits = ["apple", "banana", "orange"];
console.log(fruits[0]); // "apple"
console.log(fruits[2]); // "orange"

Array vs object: the key difference

An array is the right choice when the order of items matters and they’re accessed by position. An object is the right choice when each value has a specific “name” and access order isn’t the main point.

If you need to check a JSON array’s structure before using it in your code, paste it into JSON Validator to visualize it better.