A JSON array is used to store a list of values.
Use an array whenever you have more than one value for the same piece of information.
For example, if a student has several favorite subjects, you can store them in an array.
{
"favoriteSubjects": [
"Math",
"Science",
"Art"
]
}
Here, favoriteSubjects contains three values, so an array is used.
An array can contain objects. This is useful when you have a list of similar items.
For example, a classroom may have many students.
{
"students": [
{
"name": "Emma",
"grade": 8
},
{
"name": "Noah",
"grade": 9
}
]
}
Here:
students is an array.Arrays can also contain other arrays.
For example, each row of seats in a classroom can be stored as an array.
{
"seating": [
["Anna", "Ben"],
["Chris", "David"]
]
}
Each inner array represents one row of seats.
Every array must start with [ and end with ].
✅ Correct
[
"Red",
"Green",
"Blue"
]
❌ Wrong
{
"Red",
"Green",
"Blue"
}
Why is it wrong? Lists of values must use square brackets, not curly braces.
Each value in an array must be separated by a comma.
✅ Correct
[
"Dog",
"Cat",
"Rabbit"
]
❌ Wrong
[
"Dog"
"Cat"
"Rabbit"
]
Why is it wrong? The values are missing commas.
An array does not have to contain any values.
✅ Correct
[]
This is called an empty array.
For example:
{
"notifications": []
}
This means there are currently no notifications.
An array can store strings, numbers, booleans, objects, arrays, or even null.
✅ Example
[
"Apple",
25,
true,
null
]
Although this is valid JSON, it is usually better to store similar types of data together to keep your data organized.
An array can contain another array or an object.
Array inside an array
[
["A", "B"],
["C", "D"]
]
Object inside an array
[
{
"name": "Leo"
},
{
"name": "Mia"
}
]
Each item in an array has a position called an index.
JSON itself does not define indexing. However, when arrays are used in programming languages such as JavaScript or Python, indexing usually starts at 0.
For example:
[
"Apple",
"Banana",
"Orange"
]
| Index | Value |
|---|---|
| 0 | "Apple" |
| 1 | "Banana" |
| 2 | "Orange" |
So:
"Apple""Banana""Orange"Note: JSON is only a data format. The programming language you use to read JSON decides how array indexing works. Most modern programming languages start counting from 0.
Use an array whenever you need to store multiple values.
Examples include:
[ ].[]).