JSON Syntax

Last updated:

JSON syntax is defined by RFC 8259 (December 2017) and ECMA-404. A valid JSON value is exactly 1 of 6 types: string (double-quoted only), number (integer or decimal, no octal/hex), boolean (true/false lowercase), null, object, or array. JSON forbids 4 things you find in JavaScript: comments, trailing commas, single-quoted strings, and unquoted object keys. Numbers have no size limit in the spec, but most parsers silently lose precision on integers beyond 53 bits. This guide covers all 6 value types with examples, string escape sequences (8 required, \uXXXX for Unicode), number format rules, object and array syntax, and the 5 most common parser-breaking errors: trailing commas, single quotes, missing quotes on keys, comments, and bare undefined.

Validate JSON syntax online

Paste your JSON to check syntax instantly — highlights the exact line and position of every error.

Open JSON Validator

JSON values

Any JSON document is a single value. That value is one of six types:

"a string"          // string
42                  // number
3.14                // number (decimal)
true                // boolean
false               // boolean
null                // null
{"key": "value"}    // object
[1, 2, 3]           // array

Strings

JSON strings must be enclosed in double quotes. Single quotes are not valid.

// Valid
"hello"
"hello world"
"it's fine"          // single quote inside is OK
"say \"hi\""       // escaped double quote inside

// Invalid
'hello'              // single quotes not allowed
hello                // unquoted string

Special characters that must be escaped inside a JSON string:

CharacterEscape sequence
Double quote\"
Backslash\\
Newline\n
Carriage return\r
Tab\t
Unicode code point\uXXXX

Numbers

JSON numbers are written without quotes. They can be integers, decimals, or use scientific notation:

42          // integer
-7          // negative integer
3.14        // decimal
1.5e10      // scientific notation
-2.1E-3     // negative scientific

// Invalid
07          // leading zero (not allowed)
0xFF        // hex (not allowed)
NaN         // not a JSON value
Infinity    // not a JSON value

Booleans and null

Boolean values are the literals true and false (lowercase only). The absence of a value is represented by null.

true
false
null

// Invalid
True        // wrong case
False       // wrong case
NULL        // wrong case
undefined   // not a JSON value

Objects

A JSON object is an unordered collection of key-value pairs enclosed in curly braces. Keys must be strings. Key-value pairs are separated by commas. The last pair must not have a trailing comma.

{
  "name": "Alice",
  "age": 30,
  "active": true
}

// Invalid — trailing comma after last pair
{
  "name": "Alice",
  "age": 30,     ← trailing comma not allowed
}

// Invalid — unquoted key
{
  name: "Alice"  ← key must be a string
}

Duplicate keys are technically allowed by the spec but should be avoided — parsers handle them differently (some keep the last, some keep the first).

Arrays

A JSON array is an ordered list of values enclosed in square brackets. Values are separated by commas. Like objects, no trailing comma is allowed.

[1, 2, 3]
["a", "b", "c"]
[true, null, 42, "mixed"]
[[1, 2], [3, 4]]          // nested arrays
[{"id": 1}, {"id": 2}]    // array of objects

// Invalid — trailing comma
[1, 2, 3,]   ← not allowed

Nesting

Objects and arrays can be nested to any depth:

{
  "user": {
    "id": 1,
    "name": "Alice",
    "roles": ["admin", "editor"],
    "address": {
      "city": "London",
      "country": "UK"
    }
  }
}

Whitespace

Whitespace (spaces, tabs, newlines) is allowed between tokens and has no semantic meaning. These two documents are identical:

// Pretty-printed (same data as below)
{
  "name": "Alice",
  "age": 30
}

// Minified (same data as above)
{"name":"Alice","age":30}

Common JSON syntax errors

ErrorInvalidFixed
Trailing comma{"a":1,}{"a":1}
Single-quoted string{'key':'val'}{"key":"val"}
Unquoted key{key:"val"}{"key":"val"}
JavaScript comment{"a":1 // note}Remove comment
Missing comma{"a":1 "b":2}{"a":1,"b":2}
Undefined value{"a":undefined}Use null

Validate JSON syntax online

Paste your JSON into the JSON Validator to check for syntax errors. The validator reports the exact line and column of each error. Use the fix invalid JSON guide for step-by-step repair instructions.

Frequently asked questions

What are the six value types in JSON?

JSON has six types: string (double-quoted text), number (integer or decimal), boolean (true or false), null, object (key-value pairs in curly braces), and array (ordered list in square brackets). Objects and arrays can contain any of the six types including other objects and arrays.

Does JSON allow single-quoted strings?

No. JSON requires double quotes for all strings — keys and values. Single-quoted strings like 'hello' are not valid JSON. Single quotes inside a double-quoted string are fine: "it's valid" is a valid JSON string.

Are JSON keys required to be strings?

Yes. JSON object keys must be double-quoted strings. Unquoted keys like {name: "Alice"} and numeric keys like {1: "one"} are invalid JSON. Use {"1": "one"} for numeric-looking keys.

Does JSON support comments?

No. JSON supports neither // nor /* */ comments. Use YAML or TOML if you need comments in config files. For JSON config files specifically, VS Code supports JSONC (JSON with Comments) in *.jsonc files.

What is the maximum nesting depth in JSON?

The spec sets no limit. Python's json module defaults to ~1000 levels. Most parsers use recursion internally and may stack overflow at extreme depths. Well-designed JSON data is typically shallow — under 10 levels deep.

What characters must be escaped in JSON strings?

Required escapes: \" (double quote), \\ (backslash), \n (newline), \r (carriage return), \t (tab). All control characters (U+0000–U+001F) must be escaped. Most other Unicode characters can appear literally.

Further reading and primary sources