JSON Syntax

Beginner
⏱️ 9 min read
📚 Updated: May 2026
Text format

What you’ll learn

JSON (JavaScript Object Notation) is a lightweight way to move structured data between systems as plain text. The syntax looks like JavaScript literals, but the grammar is stricter so every parser agrees on the same bytes.

Here you will see the building blocks—braces, brackets, colons, commas, and the six value types—then a full example and how to load it with JSON.parse in the browser.

What is JSON?

JSON is a text-based format built from key–value pairs and ordered lists. Servers send it in HTTP bodies; browsers and runtimes turn it into native types. The formal rules live in RFC 8259; this page is a practical tour of the surface syntax.

Why JSON works well

Lightweight

Fewer delimiters than XML for the same record shape, which keeps payloads smaller.

Language independent

The same UTF‑8 text parses in JavaScript, Python, Go, Rust, and most other stacks.

Structured

Objects and arrays nest cleanly so you can model tables, trees, and documents in one payload.

Easy to parse

Strict grammar means generic parsers (JSON.parse, json.loads, etc.) behave consistently.

JSON syntax rules

Read this checklist once; when something fails validation, one of these rules is usually the culprit.

  1. Six value types — Every value is a string, number, object, array, boolean, or null. See the data types page for details and edge cases (for example strict number rules).
    • String — Unicode text in double quotes, with escapes as needed.
    • Number — Decimal digits; optional -, fraction, and exponent.
    • Boolean — Literals true or false (never quoted).
    • Array[ ] around a comma-separated list of values.
    • Object{ } around comma-separated "key": value pairs.
    • Null — Literal null (lowercase).
  2. Key–value pairs — Inside objects, each key is a JSON string, followed by :, then the value. Members are separated by , with no trailing comma after the last one.
  3. Arrays — Values in [ ] are separated by commas; elements may mix types.
  4. Objects — Unordered maps in { }; keys must be unique within one object.

Example of JSON syntax

One object describes a person: primitives for simple fields, an array for hobbies, a nested object for address, and null for an unknown boolean state.

JSON
{
  "name": "John Doe",
  "age": 30,
  "isStudent": false,
  "hobbies": ["reading", "traveling", "photography"],
  "address": {
    "street": "123 Main St",
    "city": "Anytown",
    "country": "USA"
  },
  "isMarried": null
}

How to read it

Object keys
Each member name is a JSON string in double quotes: "name", "age", "isStudent", and "isMarried" label scalar fields on the person object.
Scalar values
The literals beside those keys use four JSON value kinds: "John Doe" (string), 30 (number), false (boolean), and null (no value / unknown).
"hobbies"
Value is an array in [ ]: three strings in order, separated by commas.
"address"
Value is a nested object in { } with its own quoted keys ("street", "city", "country") and string values.

Parsing JSON in JavaScript

Use JSON.parse to turn JSON text into a plain object you can read with dot or bracket notation.

JavaScript
const jsonString = '{"name": "John Doe", "age": 30}';
const data = JSON.parse(jsonString);
console.log(data.name); // "John Doe"
console.log(data.age); // 30

For malformed input, JSON.parse throws SyntaxError. The JSON.parse() tutorial covers errors, the reviver callback, and safe handling. To serialize back to text, use JSON.stringify().

Key takeaways

1

Objects use { } with double-quoted keys; arrays use [ ]; members and elements are comma-separated.

2

Only six value types exist; everything else must be encoded as one of them (for example dates as strings).

3

JSON.parse is the standard way to consume JSON text in the browser; pair it with validation for data you did not author.

Frequently asked questions

Yes. Keys are JSON strings and must use double quotes. Single quotes or bare identifiers are not valid JSON.
The grammar allows a top-level string, number, boolean, or null as well as objects and arrays. Many APIs still choose { } or [ ] at the root for clarity.
No. Only double-quoted strings are allowed. This is one of the most common differences from JavaScript object literals.
Insignificant whitespace (space, tab, line break) may appear between tokens. Inside a string, whitespace is literal data or must be escaped.

Next: JSON Data Types

After syntax, zoom in on strings, numbers, booleans, null, objects, and arrays the way parsers see them.

JSON Data Types →
Did you know?

JSON strings are sequences of Unicode code points in double quotes. Line breaks and control characters must use escapes such as \n and \uXXXX; raw newlines inside a string make the whole document invalid.

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.

10 people found this page helpful