JSON Syntax Reference
The complete rules for writing valid JSON, with examples of correct and incorrect usage.
Root Value
A JSON document can be any single value: an object, array, string, number, boolean, or null.
// All of these are valid complete JSON documents:
{"key": "value"}
[1, 2, 3]
"hello"
42
true
nullObjects
An object is an unordered collection of key-value pairs, wrapped in curly braces.
{
"key": "value",
"number": 42,
"nested": {
"inner": true
}
}- Keys must be double-quoted strings
- Key-value pairs are separated by commas
- No trailing comma after the last pair
- Duplicate keys are technically allowed by the spec but produce undefined behavior — avoid them
Arrays
An array is an ordered list of values, wrapped in square brackets.
[1, "two", true, null, {"nested": "object"}, [3, 4]]- Items can be any JSON value type (including mixed types)
- Separated by commas, no trailing comma
- Arrays can contain other arrays or objects
Strings
Strings are sequences of Unicode characters wrapped in double quotes.
"Hello, world!"
"Line 1\nLine 2"
"Path: C:\\Users\\name"
"Unicode: \u0041" // = "A"Required escape sequences inside strings:
\\"— double quote\\\\— backslash\\n— newline (LF)\\r— carriage return (CR)\\t— horizontal tab\\uXXXX— Unicode code point (4 hex digits)
Numbers
42 // integer
-7 // negative
3.14 // decimal
1.5e10 // scientific notation
-2.5E-3 // negative scientificJSON has no separate integer type — all numbers are IEEE 754 double-precision floats. NaN and Infinity are not valid JSON numbers.
Booleans and Null
true
false
nullThese must be lowercase. True, False, NULL are all invalid.
Whitespace
Space, tab, newline, and carriage return can appear anywhere between tokens. Whitespace inside strings is significant.
Related
- JSON Validator — check your syntax
- Common Errors
- JSON Data Types in depth