JSON vs JSON5 vs JSONC: Differences and When to Use Each
· 4 min read
JSON is the strict data format every language can parse; JSONC is JSON plus comments (and, in most parsers, trailing commas), used for config files like VS Code settings and tsconfig.json; JSON5 goes further with single quotes, unquoted keys, hex numbers and more. Use JSON for anything exchanged between programs, and JSONC or JSON5 only for hand-written config read by a parser that explicitly supports it.
Feature comparison
| Feature | JSON | JSONC | JSON5 |
|---|---|---|---|
// and /* */ comments | No | Yes | Yes |
| Trailing commas | No | Usually (parser-dependent) | Yes |
| Single-quoted strings | No | No | Yes |
| Unquoted keys (identifiers) | No | No | Yes |
Hex numbers (0xFF) | No | No | Yes |
Leading/trailing decimal point (.5, 5.) | No | No | Yes |
Leading + sign | No | No | Yes |
Infinity, NaN | No | No | Yes |
| Multi-line strings (escaped line break) | No | No | Yes |
| Specification | RFC 8259 / ECMA-404 | No formal spec; defined by parsers (e.g. Microsoft's jsonc-parser) | json5.org spec (v1.0.0) |
| Native parser in browsers/Node | JSON.parse | No | No |
The same config in each format
{
"name": "api",
"port": 8080,
"retries": 3,
"allowedOrigins": ["https://example.com"]
}{
// Service name used in logs
"name": "api",
"port": 8080,
/* Retries for upstream calls */
"retries": 3,
"allowedOrigins": ["https://example.com"],
}{
// Service name used in logs
name: 'api',
port: 0x1F90, // 8080
retries: 3,
allowedOrigins: ['https://example.com',],
}Where you meet each one
JSON
API requests and responses, message queues, data files, package.json, browser storage. Its strictness is the point: any compliant parser in any language reads it the same way, and there is no ambiguity about what a document means.
JSONC
VS Code's settings.json, launch.json and tasks.json, TypeScript's tsconfig.json and jsconfig.json, and Dev Container devcontainer.json. The common thread is files people edit by hand and want to annotate. Some tools that accept comments in their config still read plain JSON elsewhere: package.json, for example, must be strict JSON.
JSON5
Config for some JavaScript tooling (Babel parses .babelrc with a JSON5 parser, and Renovate supports renovate.json5), and some game and app configs. It is more comfortable to write but you need the json5 library to read it.
Parsing JSONC and JSON5 in code
// npm install json5 jsonc-parser
import JSON5 from "json5";
import { parse as parseJsonc } from "jsonc-parser";
JSON5.parse("{name: 'api', port: 0x1F90,}"); // { name: "api", port: 8080 }
parseJsonc('{ "a": 1, // note\n }'); // { a: 1 }
// Convert either to strict JSON for other tools
const strict = JSON.stringify(JSON5.parse(source), null, 2);In Python, the standard json module only reads strict JSON; third-party packages such as json5 handle JSON5. Avoid stripping comments with a regular expression: a // inside a string such as a URL will be removed too.
Converting to strict JSON
Comments are lost when you convert, because JSON has nowhere to put them. Everything else maps cleanly, except Infinity and NaN, which have no JSON equivalent and usually become null. Our JSON formatter has a JSON5 input mode that accepts JSON5 and JSONC and shows the strict JSON it means, with a note for anything that changed. For a file with only a few stray comments or trailing commas, the JSON fixer removes them and shows a diff.
Which should you choose?
- Data exchanged between systems: JSON, always. Every consumer can read it and nobody has to guess which extensions are allowed.
- A config file your tool already defines: whatever the tool documents. Do not add comments to a file the tool reads as strict JSON.
- A new config format you are designing: JSONC is a modest, widely understood step. If you want much friendlier syntax, consider YAML or TOML, which have broader ecosystem support than JSON5.
- Data you will validate with JSON Schema: schemas apply to the parsed data, so they work with any of the three once parsed. See the JSON Schema beginner guide.
If a strict parser rejects a file you thought was JSON, run it through the validator. An error at a / or at a closing bracket after a comma is the giveaway that it is really JSONC or JSON5.
FAQ
Can JSON have comments?
No. Standard JSON (RFC 8259) has no comment syntax. Files that allow comments, such as tsconfig.json, are JSONC and need a JSONC-aware parser.
Is JSON5 valid JSON?
Not in general. Every JSON document is valid JSON5, but JSON5 documents that use its extensions (comments, single quotes, unquoted keys) fail in a strict JSON parser.
Is tsconfig.json JSON or JSONC?
TypeScript parses tsconfig.json leniently, allowing comments and trailing commas, so in practice it is JSONC.
How do I convert JSON5 to JSON?
Parse it with a JSON5 parser and serialize with JSON.stringify, or paste it into the JSON formatter in JSON5 mode. Comments are dropped.
Should I use JSON5 for APIs?
No. APIs should send strict JSON so every client can parse it with built-in tools.

