Reference · 8 min read
JSON Syntax Rules
JSON (JavaScript Object Notation) is defined by RFC 8259. It has a small, strict set of rules. This page covers every rule — from data types to string escaping — so you know exactly what valid JSON looks like.
The 6 JSON Value Types
A JSON value must be exactly one of these six types:
string"Hello, world!"
A sequence of Unicode characters wrapped in double quotes.
number42
An integer or floating point number. No quotes. Hex, octal, and NaN are not valid.
booleantrue / false
Lowercase only. True, False, TRUE are not valid JSON.
nullnull
Represents an absent value. Lowercase only — Null and NULL are invalid.
object{"key": "value"}An unordered collection of key-value pairs. Keys must be strings in double quotes.
array[1, "two", true]
An ordered list of values. Values can be of any valid JSON type.
String Rules
Strings are the strictest part of JSON syntax. The rules:
- Double quotes only: Strings must be wrapped in double quotes. Single quotes are not valid JSON: 'hello' is invalid, "hello" is valid.
- Escape special characters: Certain characters inside strings must be escaped with a backslash: \" (quote), \\ (backslash), \n (newline), \t (tab), \r (carriage return), \/ (forward slash).
- Unicode escapes: Any Unicode character can be represented as \uXXXX where XXXX is the four-digit hex code.
- No raw control characters: Control characters (ASCII 0–31) must be escaped. You cannot include a raw newline or tab inside a string.
// Valid string examples "Simple string" "String with \"quotes\" inside" "Line one\nLine two" "Tab\there" "Unicode: \u0041" // = "A"
Number Rules
Valid numbers
0 42 -7 3.14 1.5e10 2.5E-3
Invalid numbers
NaN Infinity 0x1F (hex) 077 (octal) +42 (leading +) .5 (leading dot)
Numbers cannot have leading zeros (except 0.5). NaN and Infinity are JavaScript concepts — they are not part of JSON.
Object Rules
- Keys must be strings in double quotes
- Key-value pairs are separated by a colon :
- Multiple pairs are separated by commas
- No trailing comma after the last pair
- No duplicate keys (technically allowed by spec but discouraged — parsers may ignore duplicates)
- Order of keys is not guaranteed
{
"name": "Alice",
"age": 30,
"active": true,
"address": {
"city": "New York"
}
}Array Rules
- Values are wrapped in square brackets [ ]
- Values are separated by commas
- No trailing comma after the last element
- Values can be of any valid JSON type — including mixed types
- Arrays can be empty: []
- Arrays can be nested: [[1, 2], [3, 4]]
[
"string",
42,
true,
null,
{"nested": "object"},
[1, 2, 3]
]Whitespace & Formatting
Whitespace (spaces, tabs, newlines) is ignored between tokens in JSON. Both of these are identical to a parser:
Minified
{"name":"Alice","age":30}Beautified
{
"name": "Alice",
"age": 30
}Check Your JSON Against These Rules
Paste your JSON into the free validator — get an instant verdict with precise error messages.
Validate JSON NowRelated Guides
How to Validate JSON
Step-by-step guide to JSON syntax checking online.
How to Fix Invalid JSON
Solutions for every common JSON error with before/after examples.
Validate JSON in JavaScript
JSON.parse, try/catch, and TypeScript examples.
JSON Parse Error Reference
What every JSON parse error means and how to fix it.
JSON Lint – Online JSON Linter
Lint JSON for syntax errors against RFC 8259.