Two relaxed dialects, two different rule sets
“JSON with comments” covers two formats that are easy to confuse:
- JSONC is plain JSON plus
//and/* */comments and trailing commas. It is whattsconfig.json,.vscode/settings.json,devcontainer.jsonand many ESLint and Biome configs use. Keys and strings still need double quotes. - JSON5 goes further: unquoted keys, single-quoted strings, hexadecimal numbers, leading or trailing decimal points (
.5,5.), explicit+signs,InfinityandNaN. Babel configs, some build tools andpackage.json5use it.
A file that is valid JSON5 can be invalid JSONC. TypeScript will refuse a tsconfig.json with an unquoted key even though a JSON5 parser would accept it, so it matters which rules you validate against.
Choosing the dialect
The Variant option controls this. Auto-detect looks for JSON5-only syntax (an unquoted key, a single quote, a hex literal, Infinity) after ignoring comments and string contents; if it finds any, the input is checked as JSON5, otherwise as JSONC. Pick JSONC (JSON with comments) explicitly when validating a tsconfig.json or VS Code settings file, so that an accidental unquoted key is reported instead of silently accepted. Pick JSON5 when the consumer really is a JSON5 parser. If a file contains nothing but standard JSON, both modes accept it, and you may prefer the stricter JSON validator to confirm it will also load with JSON.parse.
The other options on the formatter, Quote keys and Trailing commas, change the formatted output only. They have no effect on whether the input passes.
How the two parsers report problems
In JSON5 mode the input goes through the reference json5 parser, which stops at the first problem and names the character it did not expect (“Invalid character ‘p’”). In JSONC mode the error-tolerant jsonc-parser from VS Code is used, and it keeps going after a problem, so you can see up to twenty issues at once, each at its own line and column. The first error is highlighted in the editor and the previous good output stays visible but dimmed, which makes it easy to compare against what you just broke.
When the input is valid, Prettier formats it and keeps every comment in place.
What passing does not prove
This is a syntax check. It does not know which keys TypeScript or VS Code accept, so a misspelled "stict": true in compilerOptions passes here and is quietly ignored by the compiler. Duplicate keys are not flagged in these dialects either; the last one wins in both parsers. For that kind of checking, rely on the editor’s built-in schema support or run tsc --showConfig. Your config never leaves the browser while you validate it, so internal paths and registry tokens stay on your machine.
Examples
Missing comma in a JSON5 config
Invalid: JSON5 allows the unquoted keys and trailing commas, but the missing comma after ‘shop-api’ is reported where ‘port’ begins.
{
name: 'shop-api'
port: 8080,
hosts: ['api.example.com', 'api-eu.example.com',],
}Line 3, column 3: Invalid character 'p'Unquoted key in a tsconfig.json
Invalid: comments and trailing commas are fine in JSONC, but compilerOptions needs double quotes, exactly as TypeScript would complain.
{
// compiler settings for the API package
compilerOptions: {
"strict": true,
"target": "ES2022",
},
}Line 3, column 3: Unexpected character
Line 3, column 18: Expected a property name in double quotes
Line 4, column 19: Expected a value
Line 6, column 4: Unexpected content after the end of the valueA valid VS Code settings file
Comments and the trailing comma are accepted under JSONC rules and kept in the formatted output.
{
// editor
"editor.formatOnSave": true,
"editor.rulers": [80, 120],
/* language overrides */
"[python]": { "editor.tabSize": 4 },
}{
// editor
"editor.formatOnSave": true,
"editor.rulers": [80, 120],
/* language overrides */
"[python]": { "editor.tabSize": 4 }
}
Common errors and how to fix them
| Error | Cause | Fix |
|---|---|---|
Expected a property name in double quotesExplained | A key is unquoted or single-quoted while validating as JSONC. | Wrap the key in double quotes, or switch the Variant to JSON5 if your tool really reads JSON5. |
Invalid character 'p' | The JSON5 parser reached a character that cannot appear at that position, most often because a comma is missing on the previous line. | Look just before the reported column for a missing comma or an unclosed quote. |
Invalid end of input | A string, object or array is still open when the file ends, often an unterminated quote. | Close the string or bracket that opens closest to the end of the file. |
Unterminated block comment | A /* comment has no closing */ in a JSONC file. | Add */ where the comment should end. |
Frequently asked questions
Is tsconfig.json JSON5 or JSONC?
JSONC. TypeScript accepts comments and trailing commas but still requires double-quoted keys and strings, so validate it with the JSONC variant.
Why does my file pass as JSON5 but fail as JSONC?
It uses a JSON5-only feature such as an unquoted key, single quotes, a hex number or Infinity. JSONC allows only comments and trailing commas on top of standard JSON.
Can I convert JSON5 to strict JSON?
Yes. The JSON5 to JSON converter parses the file and writes standard JSON; comments are dropped because JSON cannot hold them.
Does validation remove my comments?
No. Validation never changes the input, and formatting keeps comments too. Only minifying or sorting keys drops them, and the tool tells you when that happens.