JSON (JavaScript Object Notation) is the dominant data format for APIs, configuration files, and data exchange on the web. Its syntax is deliberately minimal — but that minimalism cuts both ways. There are very few rules, but every single one is enforced strictly. One missing comma or one unquoted key breaks the entire document.
The six JSON data types
JSON supports exactly six value types. Nothing else is valid:
- String — text wrapped in double quotes:
"hello" - Number — integer or decimal, no quotes:
42,3.14,-7 - Boolean —
trueorfalse(lowercase, no quotes) - Null — the absence of a value:
null(lowercase, no quotes) - Array — an ordered list in square brackets:
[1, 2, 3] - Object — a collection of key/value pairs in curly braces:
{"key": "value"}
"2026-02-05T12:00:00Z"). Functions cannot be stored in JSON at all.The rules every valid JSON document must follow
- Keys must be strings — wrapped in double quotes, always. No bare words.
- Strings must use double quotes — single quotes are not valid JSON.
- No trailing commas — the last item in an object or array must not have a comma after it.
- No comments — JSON has no comment syntax. Neither
// thisnor/* this */is valid. - Numbers are unquoted —
42is a number;"42"is a string. They are different types. - Booleans and null are lowercase —
True,False,NULLare all invalid.
The most common JSON mistakes
1. Trailing comma
The trailing comma is the most frequent JSON error, especially for developers coming from JavaScript where trailing commas are allowed.
2. Single quotes instead of double quotes
3. Unquoted keys
4. Comments
If you need comments in a configuration file, consider using JSONC (JSON with Comments) or YAML instead. Many editors (including VS Code's settings.json) support JSONC as a non-standard extension.
5. Undefined, NaN, and Infinity
JavaScript values like undefined, NaN, and Infinity are not valid JSON. If a JavaScript object contains these values, JSON.stringify() will either omit the key or replace the value with null.
JSON.stringify({a: undefined}) returns {} — the key is silently dropped. JSON.stringify({a: NaN}) returns {"a": null}. This can cause subtle data loss when serialising JavaScript objects.How to find and fix JSON errors
The fastest approach is to paste the invalid JSON into a formatter. A good JSON formatter will highlight the exact line and position of the error and show the specific rule that was violated. Common error messages and what they mean:
- "Unexpected token ," — trailing comma in an object or array
- "Unexpected token }" — often a missing comma between properties
- "Unexpected token '" or "Unexpected token identifier" — single-quoted strings or unquoted keys
- "Unexpected end of JSON input" — unclosed bracket, brace, or string