A JSON array of objects is a list of records: square brackets around a comma-separated list of objects, where each object holds key-value pairs. It is the most common shape for API responses, exports and fixtures, because it maps directly to rows in a table.
This guide shows the syntax, the mistakes that make it invalid, and how to read, filter and convert an array of objects in JavaScript, Python and a spreadsheet.
What a JSON array of objects looks like
An array starts with [ and ends with ]. Each item is an object in curly braces, and items are separated by commas. There is no comma after the last item.
[
{ "id": 1, "name": "Ada", "email": "ada@example.com", "active": true },
{ "id": 2, "name": "Grace", "email": "grace@example.com", "active": false },
{ "id": 3, "name": "Linus", "email": "linus@example.com", "active": true }
]A JSON document can be an array at the top level. RFC 8259 allows any value as the root, so the file above is valid on its own. Many APIs still wrap the array in an object, such as {"users": [...]}, so they can add paging fields like next or total later without breaking clients.
Rules and common mistakes
- Keys and string values use double quotes.
{'id': 1}is not JSON. - No trailing comma after the last object or the last key.
- Objects in the same array do not have to share keys, but code is simpler when they do. A missing key is usually read as undefined or None.
- Order is kept. An array is ordered, so the first object stays first. Key order inside each object carries no meaning.
- Use
nullfor an empty value, not an empty string, when the field has no value.
If an array refuses to parse, paste it into the JSON validator to find the line and column of the problem.
Loop, filter and find items in JavaScript
JSON.parse turns the text into a normal JavaScript array, so the usual array methods work.
const users = JSON.parse(text)
for (const user of users) console.log(user.name)
const active = users.filter((u) => u.active) // two objects
const names = users.map((u) => u.name) // ["Ada", "Grace", "Linus"]
const grace = users.find((u) => u.id === 2) // the Grace object
const byId = Object.fromEntries(users.map((u) => [u.id, u]))To turn an array back into JSON text, use JSON.stringify(users, null, 2). See JSON in JavaScript for parsing and stringifying in depth.
Read an array of objects in Python
json.load returns a list of dicts. List comprehensions handle most filtering.
import json
with open("users.json") as f:
users = json.load(f)
active = [u for u in users if u["active"]]
names = [u["name"] for u in users]
grace = next(u for u in users if u["id"] == 2)
email = users[0].get("phone", "none") # safe lookup for a missing keyJSON in Python covers reading files, writing them back and handling errors.
Query it without code
For a quick look, a query language is faster than a script. Each line below runs against users.json:
| Goal | JSONPath | jq |
|---|---|---|
| All names | $[*].name | .[].name |
| Active users | $[?(@.active == true)] | .[] | select(.active) |
| Count | Not supported | length |
| Pick two fields | Not supported | map({id, name}) |
Try JSONPath in the JSONPath tester and jq filters in the jq tester.
{⌄}JSON ViewerExplore a large array as a collapsible tree with item counts.→Convert an array of objects to CSV or Excel
Because each object is a record, an array of objects converts cleanly to a table. Keys become column headers and each object becomes a row. Nested objects are flattened into dot-path columns such as plan.tier.
Going the other way, the CSV to JSON converter turns a spreadsheet export back into an array of objects.
Describe it with JSON Schema
To validate an array of objects, use type: "array" with an items schema that describes one object. Every element is checked against it.
{
"type": "array",
"items": {
"type": "object",
"required": ["id", "name"],
"properties": {
"id": { "type": "integer" },
"name": { "type": "string" },
"active": { "type": "boolean" }
}
}
}Generate a starting schema from your data with the JSON Schema generator, then check other files against it with the JSON Schema validator.