Values
A JSON value is one of: an object, an array, a string, a number, a boolean (true or false), or null. Any of these can be the top-level value of a JSON document — the spec does not require the root to be an object.
42
"hello"
true
null
[1, 2, 3]
{"a": 1}undefined // not a JSON value
NaN // not allowed
Infinity // not allowed
(1) // expressions don't existObjects
An object is a comma-separated list of key/value pairs wrapped in curly braces. Keys must be double-quoted strings. Values can be any JSON value. The order of keys is not significant — parsers may or may not preserve it.
{}
{"a": 1}
{"a": 1, "b": [2, 3]}
{
"deeply": {
"nested": true
}
}{a: 1} // unquoted key
{'a': 1} // single-quoted key
{"a": 1,} // trailing comma
{"a": 1 "b": 2} // missing commaDuplicate keys are allowed by the spec but the behavior is implementation-defined. Most parsers keep the last value silently. Do not rely on this.
Arrays
An array is a comma-separated list of values wrapped in square brackets. Elements can be of mixed types. The order is significant and preserved by every parser.
[]
[1, 2, 3]
["a", 1, true, null]
[[1, 2], [3, 4]][1, 2, 3,] // trailing comma
[1 2 3] // missing commas
[, 1, 2] // leading commaStrings
A string is a sequence of zero or more Unicode characters wrapped in double quotes. The double quote and the backslash must be escaped; control characters must be escaped or expressed as a \uXXXX sequence. Any other character can appear unescaped.
Escape sequences
| Escape | Meaning |
|---|---|
\" | Quotation mark |
\\ | Backslash |
\/ | Forward slash (optional, the slash needs no escape) |
\b | Backspace (U+0008) |
\f | Form feed (U+000C) |
\n | Line feed (U+000A) |
\r | Carriage return (U+000D) |
\t | Horizontal tab (U+0009) |
\uXXXX | Unicode code point in basic multilingual plane |
"hello"
"with \"quotes\""
"line\nbreak"
"snowman: \u2603"
"emoji: 😀"'single-quoted' // wrong quote
"unescaped
newline" // literal newline forbidden
"trailing\" // dangling backslash
"bad escape \x" // \x is not a valid escapeCharacters above U+FFFF (emoji, rare scripts) use UTF-16 surrogate pairs in the \uXXXX form. The character 😀 (U+1F600) is 😀. Most encoders just emit the literal UTF-8 bytes instead, which is also valid.
Numbers
A number is an optional minus sign, an integer part, an optional fractional part, and an optional exponent. JSON does not distinguish between integers and floats — both are just numbers.
0
-0
42
-273
3.14
1e10
1.5e-3
1E+9042 // leading zero
+1 // explicit plus sign
.5 // missing integer part
5. // missing fractional part
0x1F // hexadecimal forbidden
NaN // not a JSON value
Infinity // not a JSON valueThe spec places no limit on precision. In practice, parsers map numbers to the host language's double-precision float (about 15-17 significant decimal digits). Large integers like Twitter snowflake IDs lose precision — encode them as strings if exact preservation matters.
true, false, null
Three literal tokens. Lowercase only. No quotes. No alternatives (True, None, nil are not JSON).
true
false
nullTrue
FALSE
none
undefined
"true" // this is a string, not a booleanWhitespace
Whitespace (space, tab, newline, carriage return) is allowed between any two tokens. It is never required and never significant. Inside a string literal, whitespace is part of the value.
{"a":1,"b":2} // valid
{ "a" : 1 , "b" : 2 } // also valid, same valueEncoding
JSON documents exchanged over a network MUST be encoded in UTF-8, UTF-16, or UTF-32 according to RFC 8259. UTF-8 is the de facto choice for everything.
A Byte Order Mark (BOM) at the start of a UTF-8 document is forbidden by the spec but commonly present in files saved from Windows tools. Strip it before parsing — JSON.parse in Node and the browser rejects documents starting with U+FEFF.
The full grammar
The complete JSON grammar in ABNF (RFC 8259, slightly simplified for readability):
json = ws value ws
value = object / array / string / number
/ "true" / "false" / "null"
object = "{" ws "}"
/ "{" ws member *( ws "," ws member ) ws "}"
member = string ws ":" ws value
array = "[" ws "]"
/ "[" ws value *( ws "," ws value ) ws "]"
string = '"' *char '"'
char = unescaped
/ "\" ( '"' / "\" / "/" / "b" / "f"
/ "n" / "r" / "t" / "u" 4HEXDIG )
number = [ "-" ] int [ frac ] [ exp ]
int = "0" / ( %x31-39 *DIGIT )
frac = "." 1*DIGIT
exp = ( "e" / "E" ) [ "+" / "-" ] 1*DIGIT
ws = *( %x20 / %x09 / %x0A / %x0D )That is the entire spec. Twenty lines of grammar that have run the data layer of the internet since 2002.