JSON Syntax Rules — The Golden Rules
JSON has a small, precise grammar. Break any of these rules and every parser will reject the document. The rules are simple enough to memorize in five minutes.
The seven golden rules
- Keys must be double-quoted strings —
"name", notnameor'name' - Strings must use double quotes — single quotes are never valid
- No trailing commas — no comma after the last item in an object or array
- No comments — JSON has no
//or/* */syntax true,false, andnullare lowercase —True,False,Nullare all invalid- Numbers have no quotes — write
42, not"42"(unless you want a string) - The root must be a valid JSON value — object, array, string, number, boolean, or null
Valid examples
A valid object:
{
"name": "Alice",
"age": 30,
"active": true,
"score": null
}A valid array:
["apple", "banana", "cherry"]A valid nested structure:
{
"user": {
"id": 1,
"roles": ["admin", "editor"]
}
}Invalid examples and why they fail
Single quotes — invalid:
{'name': 'Alice'}Trailing comma — invalid:
{"name": "Alice", "age": 30,}Unquoted key — invalid:
{name: "Alice"}Comment — invalid:
{
"port": 3000
// This is the default port
}Uppercase boolean — invalid:
{"active": True}Why no comments in JSON?
Douglas Crockford intentionally removed comments from JSON because he observed that developers were using them to hold parsing directives — turning JSON into a configuration language with side effects. JSON is a pure data format. If you need comments, consider JSONC (used by VS Code) or YAML, or store comments as a _comment string field.
What about JSON5?
JSON5 relaxes several of these rules — it allows comments, trailing commas, single quotes, and unquoted keys. But JSON5 is not JSON. Standard parsers like JSON.parse() will reject JSON5 syntax. Use JSON5 only if your toolchain explicitly supports it.
Try it in JSON Prism
Run your JSON through the JSON Validator to catch any rule violations instantly. For a reference on which specific mistakes are most common and how to fix them, see Common JSON Mistakes.