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:

JSON does not have a date type, a function type, or an undefined type. Dates are always represented as strings (typically ISO 8601 format like "2026-02-05T12:00:00Z"). Functions cannot be stored in JSON at all.

The rules every valid JSON document must follow

{ "name": "Alice", "age": 30, "active": true, "score": null, "tags": ["admin", "user"], "address": { "city": "London", "zip": "W1A 1AA" } }

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.

// Invalid JSON — trailing comma after last property { "name": "Alice", "age": 30, }
// Valid JSON — no trailing comma { "name": "Alice", "age": 30 }

2. Single quotes instead of double quotes

// Invalid — single quotes on keys and strings {'name': 'Alice'}
// Valid {"name": "Alice"}

3. Unquoted keys

// Invalid — keys must be quoted {name: "Alice"}

4. Comments

// Invalid — JSON has no comment syntax { "host": "localhost", // database host "port": 5432 }

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.

Watch out: 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:

Tip: When debugging large JSON from an API, paste it into a formatter first. Formatters collapse valid sections and highlight exactly where the problem is — much faster than reading the raw string.