Home JSON Syntax JSON Syntax Definition
Definition and Usage JSON syntax is how you write structured data as text: curly braces for objects, square brackets for arrays, and "key": value pairs with double quotes.
Nest objects and arrays to model real API payloads. For the hard “must / must not” checklist (trailing commas, comments), see JSON Rules . For the six value kinds, see JSON Data Types .
Beginner path. Learn the building blocks → read a full nested sample → try the examples. Next: JSON Data Types .
Pieces
Building Blocks object { } holds named properties — {"id": 1}array [ ] holds an ordered list — [1, 2, 3]key : value Inside an object: quoted key, colon, then any JSON value string Always double quotes — "Ada" nesting Objects and arrays can contain other objects and arrays commas Separate siblings; never after the last item Example
Full Structure A typical record: an object with a nested object and an array.
{
"name": "Ada",
"age": 36,
"active": true,
"address": {
"city": "London",
"zip": "SW1A"
},
"skills": ["math", "code"]
} JSON Schema
Describing Structure Once the text follows JSON syntax, JSON Schema can name the expected shape—object vs array, required keys, nested properties.
{
"type": "object",
"required": ["name", "skills"],
"properties": {
"name": { "type": "string" },
"address": { "type": "object" },
"skills": {
"type": "array",
"items": { "type": "string" }
}
}
} Code
Examples Use View Output for a quick result, or Try It Yourself to edit and run in the browser.
1. Parse nested JSON 2. Read nested values 3. Array of objects Example 1 — Parse Nested JSON Feed a structured document to JSON.parse.
const text = `{
"name": "Ada",
"address": { "city": "London" },
"skills": ["math", "code"]
}`;
const user = JSON.parse(text);
console.log(user.name);
console.log(user.address.city);
console.log(user.skills[1]); How It Works The root is an object with three properties. address is a nested object; skills is an array.After parse, use dots and indexes to read values. Example 2 — Read Nested Values Same structure as a JS object—syntax maps 1:1 after parse.
const user = {
name: "Ada",
address: { city: "London", zip: "SW1A" },
skills: ["math", "code"]
};
console.log(user.address.zip);
console.log(user.skills.length);
console.log(user.skills.join(", ")); How It Works Nested objects use chained property access. Arrays expose length and methods like join. This is the shape you get from valid JSON text after parse. Example 3 — Array of Objects APIs often return a list of records—an array whose items are objects.
const text = `[
{ "id": 1, "name": "Ada" },
{ "id": 2, "name": "Grace" }
]`;
const list = JSON.parse(text);
console.log(list.length);
console.log(list[0].name);
console.log(list[1].id); How It Works The root value is an array. Each element is an object with id and name. Index into the list, then read properties on each item. Frequently Asked Questions Must JSON keys use double quotes? Yes. Every object key must be a string in double quotes. Unquoted keys are allowed in JavaScript object literals but not in JSON.
Can a JSON document start with something other than an object or array? Yes. A root value can be a string, number, boolean, null, object, or array. Many APIs still use an object or array as the root.
Are single-quoted strings valid in JSON? No. JSON strings must use double quotes. Single quotes work in JavaScript, not in JSON.
What whitespace is allowed? Space, tab, line feed, and carriage return may appear between tokens. Inside a string, use escapes such as \n instead of a raw newline.
About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
17 people found this page helpful
Helpful Share Copy link Suggestion