JSON Square Brackets vs. Curly Braces
Square brackets hold arrays. Curly braces hold objects. Learn the difference with nested examples and common mistakes.
In JSON, square brackets [] hold an array: an ordered sequence of values. Curly braces {} hold an object: named properties paired with values. Choose the structure based on what the data represents.
Use an array for a sequence
["design", "build", "test"]
Each item has a position. The first item is at index 0, the second at index 1, and so on. Array order matters: reversing this array changes its meaning.
An array can contain strings, numbers, booleans, null, objects, and other arrays. JSON syntax does not require all items to have the same type, though your application or schema may impose that rule.
Use an object for named properties
{
"name": "Alex",
"role": "Developer"
}
An object connects a property name to a value. Here, the property name has the value "Alex". Property names must be strings written in double quotes.
Object member order should not determine application behavior. This formatter nevertheless preserves the order in your input so it does not introduce unnecessary changes.
Nest arrays and objects together
{
"team": [
{ "name": "Alex", "role": "Developer" },
{ "name": "Sam", "role": "Designer" }
]
}
The outer object has a team property. Its value is an array of two objects. The path $["team"][0]["name"] points to the first person’s name. You can inspect this structure in the JSON viewer.
Can a JSON document start with square brackets?
Yes. An array is a valid top-level JSON value. So are an object, a string, a number, a boolean, and null. An API may require an object or array for its own reasons; that is a requirement of the API, not the JSON grammar.
Empty arrays and empty objects are different
[] represents an empty sequence. {} represents an object with no properties. They are both valid, but substituting one for the other can break code expecting a particular type.
Do not simply add brackets around a response to silence an error. Check the structure the receiving application expects. Wrapping {"id":1} in brackets turns one object into an array containing that object.
Common bracket errors
Every opening bracket must have a matching closing bracket of the same type. [1, 2} is invalid because an array must close with ]. An object property pair cannot appear directly inside an array without an enclosing object: use [{"id":1}], not ["id":1].
You also need commas between array items and object members, but no trailing comma. Use the validator to jump to the reported position; the actual missing bracket may be earlier in the document.
Reference: RFC 8259, objects and arrays.