JSON Syntax Rules: The Complete Reference (With Examples)
Every JSON syntax rule in one place: quotes, commas, brackets, allowed values and the mistakes that make JSON invalid, with examples.

JSON syntax comes down to a handful of rules: data is written as key/value pairs inside curly braces, keys are always double-quoted strings, values can only be one of six types, and pairs are separated by commas with no trailing comma at the end. Get those right and your JSON parses. Break one and you get a syntax error. This page is the full reference, with valid and invalid examples for each rule.
If you just want to know whether a specific block of text is valid, paste it into our JSON formatter and it will point at the exact line that fails. If you want to understand the rules so you stop hitting the error in the first place, read on.
The core JSON syntax rules in 60 seconds
Here is the whole JSON file format in one block. Everything else on this page expands on these points.
{
"name": "Nelenga",
"founded": 2024,
"active": true,
"location": null,
"tags": ["apps", "tools", "web"],
"address": {
"city": "Seginim",
"province": "Bengkulu Selatan"
}
}
The JSON syntax rules that make that valid:
- The whole thing is wrapped in one set of curly braces (an object) or square brackets (an array).
- Each entry is a
"key": valuepair. The key is a double-quoted string, then a colon, then the value. - Pairs are separated by commas. The last pair has no comma after it.
- Values are one of six types: string, number, boolean, null, array, or object.
- Strings use double quotes only. No single quotes.
- No comments, no trailing commas, no functions, no dates as a native type.
That is valid JSON. The rest is detail.
Keys must be double-quoted strings
Every key in a JSON object is a string, and every string uses double quotes. This is the rule people break most often, usually because they are copying a JavaScript object literal where unquoted keys are legal.
Valid:
{ "userId": 42 }
Invalid, because the key is not quoted:
{ userId: 42 }
Also invalid, because JSON does not accept single quotes:
{ 'userId': 42 }
JavaScript is happy with all three. JSON is a data format, not JavaScript, so it only accepts the strict double-quoted form. This trips up almost everyone moving config from a .js file into a .json file. If you are hand-editing an object copied from code, the fastest fix is to run it through a formatter that flags unquoted keys.
Keys should also be unique within the same object. Duplicates are not a hard parse error in most parsers, but the behavior is undefined: most keep the last value and silently drop the earlier one. Treat duplicate keys as a bug.
Allowed values (and which ones are not)
A JSON value can only be one of six types. This is the part of the JSON file format people underestimate.
- String:
"hello", always double-quoted. - Number:
42,-3.14,2.5e8. No leading zeros, no+sign, noNaN, noInfinity. - Boolean:
trueorfalse, lowercase, unquoted. - null: lowercase, unquoted.
- Array:
[1, 2, 3], an ordered list. - Object:
{ "k": "v" }, another set of key/value pairs.
What is not allowed as a value:
{
"date": new Date(),
"amount": undefined,
"compute": function() { return 1; },
"big": Infinity,
"hex": 0xFF
}
None of that is JSON. Dates have no native type, so they get stored as strings, usually ISO 8601 like "2026-08-17". undefined, functions, and NaN/Infinity have no representation at all. A single quote around a value is invalid too: "price": '9.99' fails, because '9.99' is not a legal JSON string.
Numbers have their own small traps. 01 is invalid (leading zero), .5 is invalid (needs a leading digit, so write 0.5), and 5. is invalid (needs a digit after the point). If you need to preserve something like a phone number with a leading zero, store it as a string.
For a deeper walk through each type and how parsers map them, see JSON data types explained. If a value itself contains a quote or a backslash, that is a separate topic covered in JSON escape characters explained.
Commas, colons, brackets and braces: placement rules
JSON has exactly four pieces of punctuation, and each has one job.
- Colon separates a key from its value:
"key": value. - Comma separates items, both object pairs and array elements.
- Curly braces
{ }wrap an object. - Square brackets
[ ]wrap an array.
Every opening bracket needs a matching closing one, and they have to nest cleanly. This is invalid because the array and object closers are crossed:
{ "list": [1, 2} ]
The most common real-world mistake is a missing comma between two pairs, or a comma where a colon should be. Whitespace (spaces, tabs, newlines) between tokens is ignored, so you can indent JSON however you like without changing its meaning.
No trailing commas, no comments
Two rules deserve their own callout because they cause more failed parses than anything else.
No trailing comma. The last element in an array or object cannot be followed by a comma. This is invalid:
{
"a": 1,
"b": 2,
}
Remove the comma after 2 and it parses. JavaScript, Python, and most linters tolerate trailing commas, so muscle memory works against you here.
No comments. JSON has no comment syntax. Neither // like this nor /* like this */ is legal. If you have seen comments in a .json file, it was a superset like JSON5 or JSONC (used by VS Code settings), not real JSON. For the workarounds people actually use, see comments in JSON.
What makes JSON invalid: the top syntax errors
If a parser rejects your JSON, it is almost always one of these:
- Trailing comma after the last item.
- Single quotes instead of double quotes, on keys or strings.
- Unquoted keys copied from JavaScript.
- Missing comma between two pairs or two array elements.
- Unescaped character inside a string, like a raw newline or an unescaped
"or backslash. - Wrong value type, like
undefined, a function, or a bare word that is nottrue/false/null. - Mismatched brackets, an opener with no matching closer.
Error messages point at the symptom, not always the cause. A parser saying Unexpected token } in JSON at position 48 usually means a trailing comma just before that brace. Unexpected string often means a missing comma between two items. The reported position is where the parser gave up, so the real error is frequently one token earlier.
Valid vs invalid JSON side by side
Same data, one legal and one not.
Valid:
{
"product": "Tandai",
"version": 2,
"beta": false,
"platforms": ["android", "ios"],
"price": null
}
Invalid:
{
'product': "Tandai",
version: 2,
"beta": False,
"platforms": ["android", "ios",],
"price": undefined,
}
Five separate errors in that second block: single quotes on product, an unquoted version key, capitalized False (JSON needs lowercase false), a trailing comma inside the platforms array, and undefined used as a value plus a trailing comma after the last pair. Fixing all five gives you the valid version above. If you want the ground rules on what JSON even is before comparing the two, what is JSON covers it.
How to check whether your JSON is valid
Three practical ways, fastest first.
Paste it into a validator. Our JSON formatter checks validity and pretty-prints your JSON. It highlights the exact line and character where parsing fails, which beats hunting through a wall of minified text by eye.
Parse it in code. In a Node or browser console, JSON.parse(yourString) throws a SyntaxError with a position if the text is invalid. In Python, json.loads(your_string) raises json.JSONDecodeError with a line and column number. Both are reliable because they use the same strict rules described here.
Use your editor. VS Code and most editors show a red squiggle under JSON syntax errors as you type in a .json file, and the Problems panel lists them. This catches trailing commas and mismatched brackets before you ever run anything.
FAQ
Can JSON have comments?
No. Standard JSON has no comment syntax, so both // and /* */ cause a parse error. Editor formats like JSONC and the JSON5 superset allow them, but a strict JSON parser will reject them. If you need notes, add a dummy string key like "_comment": "..." or keep the notes outside the file.
Are trailing commas allowed in JSON? No. You cannot put a comma after the last item in an object or array. This is the single most common cause of an invalid-JSON error, because JavaScript and Python both allow trailing commas and the habit carries over.
Does JSON require double quotes? Yes. Both keys and string values must use double quotes. Single quotes are invalid, and unquoted keys are invalid even though JavaScript object literals allow them.
What is the difference between valid JSON and a JavaScript object?
A JavaScript object literal is more relaxed: it allows single quotes, unquoted keys, trailing commas, comments, functions, and undefined. Valid JSON allows none of those. JSON is a strict text format for exchanging data, so anything that is not a string, number, boolean, null, array, or object is off-limits.