Standard JSON is strict on purpose — no comments, no trailing commas, double quotes everywhere. That strictness is perfect for data on the wire and painful for config files a human maintains. JSON5 and JSONC are extensions that relax the rules for exactly that case. This guide explains what JSON5 adds, how JSONC differs, and when each is the right choice versus plain JSON.
If you want the strict rules first, see what JSON is; this guide is about where those rules get in the way.
What JSON5 adds
JSON5 is a superset of JSON: every valid JSON document is valid JSON5, but JSON5 allows more. The additions are all aimed at human editing:
- Comments — both
// lineand/* block */. - Trailing commas —
[1, 2, 3,]and{"a": 1,}are allowed, so reordering lines does not break the file. - Unquoted keys —
{ name: "Ada" }when the key is a valid identifier. - Single-quoted strings —
'hello'as well as"hello". - Extra number formats — hexadecimal (
0xFF), leading/trailing decimal points, andInfinity/NaN. - Multi-line strings via a line-continuation backslash.
A JSON5 config might look like this:
{
// service configuration
host: 'localhost',
port: 8080,
retries: 3, // trailing comma is fine
flags: 0xFF,
}
Format and check JSON5 with the JSON5 formatter, which understands these extensions where a strict JSON tool would reject them.
JSONC: a smaller step
JSONC — “JSON with Comments” — is the dialect Visual Studio Code uses for files like tsconfig.json and settings.json. It adds just two things to JSON: comments and trailing commas. That is it — keys are still double-quoted, strings are still double-quoted. JSONC is the conservative middle ground: you get the one feature everyone actually wants (comments) without departing far from strict JSON. If all you need is to annotate a config file, JSONC is often enough.
When to use which
| Use case | Best choice |
|---|---|
| API request/response, data on the wire | Strict JSON |
| Data stored in a database or cache | Strict JSON |
| A config file you want to comment | JSONC (or JSON5) |
| A config file with lots of hand-editing | JSON5 |
The rule of thumb: strict JSON for machines, JSON5/JSONC for humans. The moment a file leaves your project and travels to another system, it should be strict JSON.
Compatibility caveats
The convenience has a cost: JSON5 and JSONC are not understood by standard JSON parsers. JSON.parse() in JavaScript and json.loads() in Python will reject a comment or a trailing comma outright. So a JSON5 file needs a JSON5-aware parser (the json5 package exists for most languages), and build tools often strip comments from JSONC before handing it to a strict parser. Never serve JSON5 from an API expecting the client to cope — convert it to strict JSON first. To do that, parse the JSON5 and re-serialise as JSON, or run it through the JSON5 formatter and then format as JSON; comments and trailing commas are dropped, leaving a clean strict document you can validate.
JSON5 vs other config formats
JSON5 is not the only way to get comments in config. YAML and TOML were designed for human-edited configuration and are common for the same reason — we compare them in JSON vs YAML vs TOML. JSON5's advantage is familiarity: it is still recognisably JSON, so a team that knows JSON needs no new mental model, and the migration from a .json to a .json5 file is trivial. If your config is already JSON and you just want comments and trailing commas, JSON5 or JSONC is the smallest possible change. For environment-specific values, see also .env files explained.
Why standard JSON stays strict
It is tempting to ask why JSON did not just include comments from the start. The strictness is deliberate and valuable: because the grammar is tiny and rigid, a JSON parser is small, fast and identical across every language, and there is exactly one way to read a document. Comments, trailing commas and alternate quote styles each add ambiguity and parser complexity, and — crucially — comments in data that travels between systems can be silently dropped or misused. So JSON stays minimal for interchange, and dialects like JSON5 layer the conveniences back on only for the human-editing case. Keeping the two concerns separate is a feature, not an oversight.
Tooling and editor support
Support varies, which affects your choice. JSONC is understood natively by VS Code for its own config files, and many editors recognise a .json5 extension for syntax highlighting. But build tools, linters and runtime parsers are a different matter: a bundler or a CI script that reads your config with a strict parser will choke on a comment. Before adopting JSON5 for a config file, confirm that every tool in the chain that reads it — not just your editor — can parse it, or that you have a build step that converts it to strict JSON first. The convenience is only worth it if the whole toolchain agrees.
Migrating a config to JSON5
Because JSON5 is a superset, migrating is painless: rename config.json to config.json5, point your loader at a JSON5 parser, and the existing content keeps working unchanged. You can then add comments and trailing commas incrementally where they help. The reverse — going back to strict JSON — is equally easy with the JSON5 formatter, which drops the extensions and leaves a clean document you can validate. That low switching cost is JSON5's real selling point over adopting a different config language entirely.
Where you already see these dialects
You have probably used these without naming them. VS Code's settings.json and tsconfig.json are JSONC — that is why you can comment them. Babel and some build tools accept a .json5 config. Recognising which dialect a file uses tells you which parser to reach for and whether you can safely add a comment. When in doubt, keep data strict and reserve the dialects for files a person edits by hand, and you will never hand a commented document to a parser that cannot read it.
Key takeaways
- JSON5 is a superset of JSON that adds comments, trailing commas, unquoted keys, single quotes and more.
- JSONC is a smaller extension — just comments and trailing commas (used by VS Code).
- Use strict JSON for data on the wire; use JSON5/JSONC only for human-edited config.
- Standard parsers reject JSON5 — convert to strict JSON before sending it anywhere.