You open a project's tsconfig.json and see comments inside a JSON file. You add a trailing comma to your package.json and the build fails. You try to explain a config value with a comment and realize JSON does not allow comments. Welcome to the confusing world of JSON variants.
Standard JSON (RFC 8259)
JSON (JavaScript Object Notation) is the universal data interchange format. It is intentionally strict:
- No comments allowed (not even
//or/* */) - All keys must be double-quoted:
{"name": "value"} - No trailing commas:
{"a": 1, "b": 2}is valid,{"a": 1, "b": 2,}is not - Strings must use double quotes — single quotes are invalid
- No multiline strings
- No hexadecimal numbers
Use standard JSON when: Data is exchanged between systems (APIs, databases, configuration files read by strict parsers).
JSONC — JSON with Comments
JSONC (JSON with Comments) is not an official standard — it is a convention used by VS Code, TypeScript, and other tools. It extends JSON with exactly two additions:
- Single-line comments:
// this is a comment - Block comments:
/* this is a block comment */ - Trailing commas are allowed
Files that use JSONC include tsconfig.json, .vscode/settings.json, and devcontainer.json. These files have a .json extension but are parsed by JSONC-aware parsers.
Important: Standard JSON.parse() in JavaScript will reject JSONC. You need a JSONC parser like jsonc-parser or the VS Code JSON module.
JSON5 — The Human-Friendly Version
JSON5 extends JSON significantly to make it more comfortable for humans to write:
- Comments (single-line and block)
- Trailing commas everywhere
- Unquoted keys:
{name: "value"} - Single-quoted strings:
'hello' - Multiline strings (with backslash line continuations)
- Hexadecimal numbers:
0xFF - Leading and trailing decimal points:
.5and5. - Infinity and NaN as values
- Additional whitespace characters
Use JSON5 when: Configuration files that humans edit frequently (like build tool configs). The json5 npm package provides parsing.
Quick Comparison
| Feature | JSON | JSONC | JSON5 |
|---|---|---|---|
| Comments | ❌ | ✅ | ✅ |
| Trailing commas | ❌ | ✅ | ✅ |
| Unquoted keys | ❌ | ❌ | ✅ |
| Single-quoted strings | ❌ | ❌ | ✅ |
| Multiline strings | ❌ | ❌ | ✅ |
| Native browser parsing | ✅ | ❌ | ❌ |
| API data interchange | ✅ | ❌ | ❌ |
Which One Should You Use?
For APIs and data exchange: Always use standard JSON. It is universally supported and every language has a built-in parser.
For TypeScript/VS Code config: Use JSONC — it is what these tools expect.
For human-authored config files: Consider JSON5 or switch to YAML/TOML, which were designed for human readability.
Need to validate or format your JSON? Our JSON Formatter & Validator checks strict JSON syntax and pinpoints the exact location of errors.