Skip to main content

Reference

JSON syntax explained

JSON has a small, strict grammar — six data types and a handful of rules. Knowing them makes it obvious why a document is invalid and how to fix it. This is the complete set, with examples.

Updated July 20265 min read

What JSON is

JSON (JavaScript Object Notation) is a text format for structured data. A JSON document is a single value — most often an object or an array, but it can also be a bare string, number, boolean, or null. Its grammar is deliberately tiny, which is why nearly every language can parse it.

The six data types

String

Text wrapped in double quotes. Single quotes are not allowed. Special characters are escaped with a backslash — \n, \t, \", and \\, plus \uXXXX for arbitrary Unicode.

"hello"
"line one\nline two"
"她说 \"hi\""

Number

A decimal number, optionally negative, with an optional fraction and exponent. There is no separate integer type, no leading +, no leading zeros, and no NaN or Infinity.

42      -3.14      6.022e23      0.5

Boolean

Exactly true or false, lowercase and unquoted.

Null

The literal null, representing "no value." JSON has no undefined.

Object

An unordered set of key/value pairs inside { }. Keys must be double-quoted strings; values can be any JSON type. Pairs are separated by commas and keys from values by a colon.

{
  "name": "Ada",
  "age": 36,
  "admin": true,
  "team": null
}

Array

An ordered list of values inside [ ], separated by commas. Values can be of mixed types, including nested objects and arrays.

[1, "two", true, null, { "nested": [] }]

The rules that trip people up

  • No trailing commas. [1, 2, 3,] and {"a": 1,} are both invalid.
  • Double quotes only. Both keys and string values must use ", never '.
  • Keys must be quoted. {name: "Ada"} is invalid; it must be {"name": "Ada"}.
  • No comments. // and /* */ are not part of JSON.
  • No functions, dates, or undefined. Dates are usually stored as ISO strings like "2026-07-16".
  • One root value. A document is a single value; you can't place two objects side by side without wrapping them in an array.

Valid vs. invalid, side by side

// ❌ invalid
{
  name: 'Ada',      // unquoted key, single quotes
  "roles": ["a",],  // trailing comma
}

// ✅ valid
{
  "name": "Ada",
  "roles": ["a"]
}

Checking your JSON

The quickest way to catch a syntax error is to run the document through a validator that points to the exact line and column of the first problem. Paste it into the JSON Viewer & Formatter — valid JSON formats and renders as a tree, and invalid JSON is flagged inline with the location so you can fix it fast. To understand a specific document's structure, seeing it as a table or a tree often helps more than reading the raw text.

Frequently asked questions

What are the data types in JSON?

JSON has six types: string, number, boolean (true/false), null, object, and array. There is no date, integer-vs-float distinction, or undefined type.

Can JSON have comments?

No. Standard JSON does not allow comments. If you need comments in a config file, look at JSON5 or JSONC — but strict JSON parsers will reject them.

Are trailing commas allowed in JSON?

No. A comma after the last element of an object or array makes the JSON invalid. This is one of the most common syntax errors.

Do JSON keys have to be in double quotes?

Yes. Object keys must be double-quoted strings. Unquoted keys and single-quoted keys are both invalid JSON.