JSON vs JSON5 vs JSONC: What's the Difference?
Standard JSON is strict by design. JSON5 and JSONC add features that make config files easier to maintain. Here's when to use each.
Why JSON variants exist
JSON was designed for data interchange between programs — a machine-readable format where brevity and parsability matter most. Those goals make JSON strict: no comments, no trailing commas, no unquoted keys. This strictness is an asset for API communication, where any ambiguity would cause problems.
But JSON is also used heavily for configuration files — files that humans edit and maintain. In that context, the strictness becomes friction. Developers want to leave comments explaining why a setting is set a certain way, add trailing commas to make diffs cleaner when adding new entries, or write readable numbers. JSON5 and JSONC address this need.
Standard JSON (RFC 8259)
Standard JSON is defined by RFC 8259 (December 2017), which supersedes earlier ECMA-404 and RFC 4627 definitions. It specifies exactly six value types:
- String (must use double quotes)
- Number (decimal only — no hex, no Infinity, no NaN)
- Object (keys must be double-quoted strings)
- Array
- Boolean (
trueorfalse, lowercase) - Null (
null, lowercase)
No comments. No trailing commas. No unquoted keys. No hexadecimal. These limitations are intentional — they keep JSON unambiguous and trivial to parse correctly.
Use standard JSON for: all API request/response bodies, data stored in databases, message queues, any context where the consumer is a standard JSON parser.
JSON5
JSON5 is a superset of JSON that adds several features borrowed from ES5 JavaScript. All valid JSON is valid JSON5 — you can incrementally adopt JSON5 features in an existing JSON file without breaking anything.
What JSON5 adds over standard JSON:
- Comments — both
// single-lineand/* block */comments - Trailing commas — after the last array element or object member
- Single-quoted strings —
'value'is valid alongside"value" - Unquoted keys —
{ name: "Alice" }is valid if the key is a valid ES5 identifier - Hexadecimal numbers —
0xFF - Leading/trailing decimal point —
.5and5. - Infinity and NaN — as numeric values
- Multi-line strings — using a backslash before a newline inside a string
// This is valid JSON5 but invalid JSON
{
// Server configuration
host: 'localhost', // unquoted key, single-quoted value
port: 8080, // trailing comma
timeout: 0xFF, // hex number
retries: 3,
}
JSON5 requires a dedicated parser: the json5 npm package for JavaScript/Node.js, or pip install json5 for Python. Standard JSON.parse() and Python's json.loads() will reject JSON5 syntax.
Use JSON5 for: application config files that developers edit by hand. It's especially common in build tool configuration, where a readable format with comments is more valuable than strict JSON compatibility.
JSONC (JSON with Comments)
JSONC is a minimal extension: it takes standard JSON and adds only one thing — // single-line and /* block */ comments. Everything else remains identical to standard JSON: double-quoted keys, no trailing commas, no unquoted keys.
JSONC is used by:
- VS Code for its user settings (
settings.json), keyboard shortcuts (keybindings.json), and extensions - TypeScript for
tsconfig.json - ESLint for
.eslintrc.json(VS Code extension mode)
// tsconfig.json uses JSONC — comments are valid here
{
"compilerOptions": {
"target": "ES2020", // ECMAScript target version
"strict": true,
"outDir": "./dist" /* compiled output directory */
}
}
Note that VS Code files like settings.json also permit trailing commas in many versions. This technically makes them JSON5 rather than strict JSONC, but the VS Code ecosystem calls them JSONC.
Use JSONC for: config files in tools that explicitly support it (VS Code, TypeScript). If you're writing a tool that reads config files, supporting JSONC (stripping comments before parsing) is a small addition that significantly improves developer experience.
Quick comparison table
| Feature | JSON | JSONC | JSON5 |
|---|---|---|---|
| Comments | ✗ | ✓ | ✓ |
| Trailing commas | ✗ | ✗ | ✓ |
| Unquoted keys | ✗ | ✗ | ✓ |
| Single-quoted strings | ✗ | ✗ | ✓ |
| Native support in browsers/runtimes | ✓ | partial | ✗ |
| Good for APIs | ✓ | ✗ | ✗ |
Converting JSON5 or JSONC to standard JSON
If you need to use a JSON5 or JSONC file as input to a tool that only accepts standard JSON, you must strip the non-standard syntax first. In Node.js:
// Convert JSON5 to standard JSON
const JSON5 = require('json5');
const fs = require('fs');
const data = JSON5.parse(fs.readFileSync('config.json5', 'utf8'));
fs.writeFileSync('config.json', JSON.stringify(data, null, 2));
Note that converting to standard JSON strips all comments — they cannot be represented in the output.
Validate standard JSON — free
The json-indent.com validator follows RFC 8259 strictly — it will flag comments and trailing commas as errors (because they are invalid in standard JSON).
Open JSON Validator →Frequently Asked Questions
What is JSON5?
JSON5 is a superset of JSON that adds syntax from ES5 JavaScript: comments (// and /* */), trailing commas, single-quoted strings, unquoted keys, hexadecimal numbers, leading and trailing decimal points, multi-line strings, and special numeric values like Infinity and NaN. All valid JSON is also valid JSON5.
What is JSONC?
JSONC (JSON with Comments) is JSON extended to allow // single-line and /* */ block comments. That's the only difference from standard JSON. JSONC is used by VS Code for its settings files (settings.json, keybindings.json) and by the TypeScript compiler (tsconfig.json).
When should I use JSON5 instead of JSON?
Use JSON5 for config files that developers edit by hand — when comments, trailing commas, and readable number formats matter more than maximum parser compatibility. Do not use JSON5 for API data exchange or any context where the consumer is a standard JSON parser without a JSON5 library.
Is JSON5 widely supported?
JSON5 requires a dedicated parser. The official json5 npm package handles it in JavaScript/Node.js. Python has the json5 library. But most languages and frameworks do not support JSON5 natively — you must explicitly add the parser. For maximum compatibility, standard JSON is always the safer choice.