JSON Syntax

Beginner
5 min read
Updated: Nov 2026
3 examples

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.

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

Full Structure

A typical record: an object with a nested object and an array.

JSON
{
  "name": "Ada",
  "age": 36,
  "active": true,
  "address": {
    "city": "London",
    "zip": "SW1A"
  },
  "skills": ["math", "code"]
}

Describing Structure

Once the text follows JSON syntax, JSON Schema can name the expected shape—object vs array, required keys, nested properties.

JSON
{
  "type": "object",
  "required": ["name", "skills"],
  "properties": {
    "name": { "type": "string" },
    "address": { "type": "object" },
    "skills": {
      "type": "array",
      "items": { "type": "string" }
    }
  }
}

Examples

Use View Output for a quick result, or Try It Yourself to edit and run in the browser.

Example 1 — Parse Nested JSON

Feed a structured document to JSON.parse.

JSON
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]);
Try It Yourself

How It Works

  1. The root is an object with three properties.
  2. address is a nested object; skills is an array.
  3. 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.

JSON
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(", "));
Try It Yourself

How It Works

  1. Nested objects use chained property access.
  2. Arrays expose length and methods like join.
  3. 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.

JSON
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);
Try It Yourself

How It Works

  1. The root value is an array.
  2. Each element is an object with id and name.
  3. Index into the list, then read properties on each item.

Frequently Asked Questions

Yes. Every object key must be a string in double quotes. Unquoted keys are allowed in JavaScript object literals but not in JSON.
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.
No. JSON strings must use double quotes. Single quotes work in JavaScript, not in JSON.
Space, tab, line feed, and carriage return may appear between tokens. Inside a string, use escapes such as \n instead of a raw newline.

Next: JSON Data Types

Learn the six value types used inside this syntax.

JSON Data Types tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

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