vs JSONC, Tested in Detail
Two ways to put comments in JSON, compared input by input with real parser output.
JSONC adds comments to JSON and little else. JSON5 adds comments plus trailing commas, unquoted keys, single quotes, more number forms and multi-line strings. The names sound interchangeable, but a file that is valid in one can fail in the other.
This page runs more than two dozen inputs through the json5 and jsonc-parser npm packages, checks how TypeScript and Prettier treat the same text, shows how to convert in each direction, and ends with a rule for choosing.
TL;DR: JSONC is JSON plus // and /* */ comments; trailing commas are optional and depend on the tool. JSON5 is a larger, versioned grammar that always allows both. Use JSONC when a tool such as VS Code or TypeScript already reads it. Use JSON5 when you control the parser and want one precise rule for hand-written files.
What JSONC Is and Where It Came From
JSONC means "JSON with Comments". According to the specification draft at jsonc.org, Microsoft introduced it informally for the configuration files of Visual Studio Code, such as settings.json, launch.json and tasks.json, and published a parser for those files, jsonc-parser. For years the format was defined mainly by what that library and the editor did.
A written specification now exists. Its repository, JSONC-org/JSONC on GitHub, was created in March 2025 under the MIT license. The project added media type guidance in March 2026 and a formal ABNF grammar in April and May 2026. The page still labels itself a draft that is subject to change, and it states its goal narrowly: to formalize as JSONC what jsonc-parser accepts with its default configuration. It is not an IETF, Ecma or ISO standard.
JSON5 followed a different route. Its 1.0.0 specification is dated March 2018 and borrows a defined set of syntax from ECMAScript 5.1. It is also outside the formal standards bodies; see standards status.
| Question | JSONC | JSON5 |
|---|---|---|
| Written specification | Draft at jsonc.org | Version 1.0.0, March 2018 |
| Base | JSON grammar (RFC 8259 rule names) plus comments | JSON plus ECMAScript 5.1 syntax |
| Comments | // and /* */ | // and /* */ |
| Trailing commas | Parsers MAY support them; not in the grammar | Required of every parser |
| Recommended extension | .jsonc | .json5 by convention |
| Reference JavaScript parser | jsonc-parser 3.3.1 (June 2024) | json5 2.2.3 (December 2022) |
| npm downloads, November 22-28, 2026 | 107,185,119 | 303,643,299 |
Download counts measure installs, including indirect ones through build tools. They do not show how many people write either format.
File Extension, Media Type and Mode Line
The jsonc.org draft recommends the .jsonc extension and says .json SHOULD be avoided. If a JSONC file keeps the .json name anyway, the draft says it SHOULD start with a mode line so people and editors can tell:
// -*- mode: jsonc -*-
{
// comments are now announced on line one
"port": 8080
}For transfer over a network, the draft says senders SHOULD use application/jsonc and SHOULD NOT use application/json, because a strict JSON consumer may reject or misread the payload. Treat that as project guidance, not a registration: the IANA registry of application/ media types, checked on November 29, 2026, lists application/json and no entry for application/jsonc or application/json5.
In practice a lot of JSONC is still named .json, because the tools that read it chose those names. That causes much of the confusion: the extension promises strict JSON and the contents are not. A program using JSON.parse fails on the first comment, and so does npm when a comment lands in package.json, with the error code EJSONPARSE and the note "package.json must be actual JSON, not just JavaScript."
Feature Matrix With Tested Output
Every row below comes from running the same string through json5 2.2.3 and jsonc-parser 3.3.1 on Node.js 24.22.1. "Errors" means jsonc-parser reported at least one error. It often returns a value anyway, and a correct caller must treat the whole parse as failed. The JSONC column uses default options; the last column adds allowTrailingComma: true.
| Input | JSON5 | JSONC default | JSONC with trailing commas |
|---|---|---|---|
// and /* */ comments | Accepted | Accepted | Accepted |
{ "a": 1, } | Accepted | Errors | Accepted |
[1, 2,] | Accepted | Errors | Accepted |
[1,,2] | Rejected | Errors | Errors |
[,] | Rejected | Errors | Errors |
{ a: 1 } | Accepted | Errors, value {} | Errors, value {} |
{ "a": 'x' } | Accepted | Errors, value {} | Errors, value {} |
0xFF | 255 | Errors, value 0 | Errors, value 0 |
.5 | 0.5 | Errors | Errors |
5. | 5 | Errors | Errors |
+1 | 1 | Errors | Errors |
Infinity, NaN | Accepted | Errors | Errors |
012 | Rejected | Errors, value 0 | Errors, value 0 |
| Backslash at end of line inside a string | Lines joined | Errors | Errors |
"\x41" | "A" | Errors, value "41" | Errors, value "41" |
\', \v or \0 escapes in a string | Accepted | Errors | Errors |
| Raw tab inside a string | Accepted | Errors | Errors |
| Form feed or non-breaking space between tokens | Accepted | Errors | Errors |
| Byte order mark at the start | Accepted | Errors | Errors |
# comment | Rejected | Errors | Errors |
Unterminated /* after the value | Rejected | Errors | Errors |
| Empty file, or only a comment | Rejected | Errors, undefined (silent with allowEmptyContent) | Same |
{} {} | Rejected | Errors | Errors |
| Missing comma between members | Rejected | Errors | Errors |
| Duplicate key | Last wins, silently | Last wins, silently | Last wins, silently |
9007199254740993 | 9007199254740992 | 9007199254740992 | 9007199254740992 |
Two rows are shared weaknesses. Neither parser warns about a duplicate key, and both lose integer precision above 253 because both produce ordinary JavaScript numbers. Store large identifiers as strings in either format. For the JSON5 side of each syntax feature, see the syntax reference.
Reproduce it
// compare.js (npm install json5 [email protected])
const JSON5 = require('json5');
const jsonc = require('jsonc-parser');
for (const text of ['{ "a": 0xFF }', '{ "a": 1, }']) {
try { console.log(JSON5.parse(text)); }
catch (e) { console.log(e.message); }
const errors = [];
const value = jsonc.parse(text, errors);
console.log(value, errors.map(e => jsonc.printParseErrorCode(e.error)));
}
// { a: 255 }
// { a: 0 } [ 'InvalidSymbol' ]
// { a: 1 }
// { a: 1 } [ 'PropertyNameExpected', 'ValueExpected' ]Fault Tolerance: The Biggest Practical Difference
JSON5.parse throws a SyntaxError on the first invalid character. jsonc.parse never throws for bad syntax. It was built for an editor, which must make sense of a half-typed file, so it recovers, keeps going and returns its best guess. Errors go into an array you pass in. Omit the array and every problem disappears:
jsonc.parse('{a:1, b: 2}'); // {} no exception
jsonc.parse('{ "port": 012 }'); // { port: 0 } no exception
jsonc.parse('{ "a": 1 "b": 2 }'); // { a: 1, b: 2 } no exceptionFor anything that is not an editor, wrap the library so it fails loudly:
const jsonc = require('jsonc-parser');
function readJsonc(text) {
const errors = [];
const value = jsonc.parse(text, errors, { allowTrailingComma: true });
if (errors.length) {
throw new SyntaxError(errors
.map(e => jsonc.printParseErrorCode(e.error) + ' at offset ' + e.offset)
.join(', '));
}
return value;
}
readJsonc('{ a: 1 }');
// SyntaxError: InvalidSymbol at offset 2, PropertyNameExpected at offset 3,
// ValueExpected at offset 7The byte order mark row matters on Windows: read the file, strip a leading U+FEFF, then parse. The encoding guide covers how those marks get there.
The __proto__ key behaves differently
We parsed { "__proto__": { "x": 1 } } with each library. json5 2.2.3, like JSON.parse, created an ordinary own property named __proto__. jsonc-parser 3.3.1, and the prerelease 4.0.0-next.2, returned an object with no own keys whose prototype was { x: 1 }, so value.x read as 1. The global Object.prototype was not changed. The library's main branch changed this on September 29, 2026 (pull request 140) so that __proto__ stays an own property, but neither published version we tested includes the change, and they were the newest stable and prerelease versions on November 29, 2026. If the input crosses a trust boundary, check keys with Object.hasOwn and validate the result; the security tutorial explains the pattern and the older JSON5 flaw fixed in 2.2.2.
Is Every JSONC File Valid JSON5?
Almost. JSON is a subset of both formats, comments use the same two forms, and trailing commas are legal JSON5. So the usual claim "rename .jsonc to .json5 and you are done" holds for ordinary files. There is one corner where the two grammars read the same bytes differently.
The JSONC grammar ends a // comment only at a carriage return or line feed. JSON5 uses the ECMAScript list of line terminators, which also includes U+2028 (line separator) and U+2029 (paragraph separator). A raw U+2028 pasted into a comment, for example from a word processor or a web page, therefore ends the comment in JSON5 and not in JSONC:
const LS = String.fromCharCode(0x2028);
const text = '{\n// note' + LS + '"x": 1,\n"a": 2\n}';
jsonc.parse(text, [], { allowTrailingComma: true }); // { a: 2 }
JSON5.parse(text); // { x: 1, a: 2 }With ordinary prose after the separator, JSON5 rejects the file instead, which is the more likely outcome. Both results are correct for their own grammar. A lint rule that bans U+2028 and U+2029 in config files removes the difference.
The reverse direction fails often. Any unquoted key, single-quoted string, hexadecimal number, leading or trailing decimal point, plus sign, Infinity, NaN or line continuation makes a JSON5 file invalid JSONC.
Trailing Commas, Tool by Tool
Trailing commas are where "it is just JSONC" stops being a useful answer. The draft makes support optional and explains why: the library it formalizes rejects them unless allowTrailingComma is turned on. The authors say a future version might require them once adoption in the JavaScript ecosystem is wide enough.
| Tool or rule | Trailing comma behavior | Basis |
|---|---|---|
| jsonc.org draft | Parsers MAY accept; the ABNF excludes them | Specification |
jsonc-parser | Error unless allowTrailingComma: true | Tested |
VS Code "JSON with Comments" mode | Accepted, with a warning | VS Code documentation |
| VS Code's own config files | Accepted without a warning, because their schemas allow it | jsonc.org appendix |
![]() tsc 5.9.3 and 7.0.2 on a tsconfig | Accepted | Tested |
Prettier 3.10.1, tsconfig.json and settings.json | Parser inferred as json; commas removed, comments kept | Tested with default options |
Prettier 3.10.1, .jsonc and .json5 | Commas added on multi-line lists and objects; in .json5 files, quotes also removed from simple keys | Tested with default options |
![]() @eslint/json, json/jsonc language | Opt in with languageOptions.allowTrailingCommas | Package README |
Deno, deno.jsonc | Comments and trailing commas allowed | Deno documentation |
![]() package.json | Strict JSON: no commas, no comments | Tested comment failure |
If a repository must satisfy several of these at once, the safe subset is comments without trailing commas. If it must satisfy package.json rules, it is neither. The trailing comma guide and the Prettier configuration guide go further.
tsconfig.json Is Neither Format Exactly
The usual description is that TypeScript reads tsconfig.json as JSONC. That is a good guide for what to write. TypeScript uses its own scanner, though, and its behavior at the edges differs from jsonc-parser. We ran the tsc command line of 5.9.3 and 7.0.2 on small test configs:
| Config content | Both compiler versions |
|---|---|
| Comments and trailing commas | No diagnostics |
| Single-quoted key and string | TS1327: String literal with double quotes expected. |
| Unquoted key | TS1327: String literal with double quotes expected. |
"maxNodeModuleJsDepth": 0x2 | No diagnostics |
The hexadecimal result is looseness inherited from a JavaScript scanner, not a documented feature, so do not depend on it. Other tools that read the same file, including Prettier, editors and your own scripts, are under no obligation to accept it. See the tsconfig guide.
Never read a tsconfig with JSON.parse. Use the compiler's configuration API, or jsonc-parser with trailing commas allowed.
Where Each Format Is Used
Files VS Code opens as JSON with Comments
The built-in extensions in the VS Code repository declare which names get the jsonc language mode. As read on November 29, 2026:
| Group | Names and extensions |
|---|---|
| Editor configuration | settings.json, launch.json, tasks.json, keybindings.json, extensions.json, mcp.json, argv.json, profiles.json, .code-workspace |
| TypeScript and JavaScript projects | tsconfig.json, jsconfig.json and variants such as tsconfig.*.json |
| Dev containers | devcontainer.json, .devcontainer.json |
| Third-party tools | .jsonc, .eslintrc, .eslintrc.json, .babelrc, .babelrc.json, babel.config.json, .jshintrc, .swcrc, bun.lock, typedoc.json |
To give any other file the same mode, add a pattern to the files.associations setting. The built-in JSON extension in that same repository registers no .json5 extension; see JSON5 in VS Code for support options.
One entry in that table is a trap worth knowing. The editor labels babel.config.json and .babelrc.json as JSONC, but the Babel documentation says those files are parsed as JSON5. Babel accepts syntax there that the editor will underline. Details are in the Babel guide.
Beyond the editor
| Project | What its documentation says |
|---|---|
| Development Container specification | Metadata can be stored in a JSON with Comments file called devcontainer.json |
| Cloudflare Wrangler | Recommends wrangler.jsonc for new projects; JSON and JSONC configs since 3.91.0 |
| Deno | Detects deno.json or deno.jsonc |
| Turborepo | Supports turbo.jsonc |
| Biome | Config file is biome.json or biome.jsonc |
| Renovate | Accepts both; recommends a .jsonc file over .json5 if you want comments, and warns that its config migration can downgrade JSON5 content |
| JSON5 reference project | Names Chromium, Next.js, Babel, Retool and WebStorm as adopters, and native support on Apple platforms |
As a rough pattern in these examples, JSONC shows up in files owned by developer tools that document it, while JSON5 is a choice a project makes along with its parser. More examples are on who uses JSON5.
Parser Availability
jsonc.org keeps a community list that is explicitly not exhaustive. Its most useful detail is whether each feature is on by default:
| Language | Library | Comments | Trailing commas |
|---|---|---|---|
JavaScript | microsoft/node-jsonc-parser (3.3.1) | Default | Optional |
Rust | dprint/jsonc-parser (crate 0.34.0) | Default | Default |
tidwall/jsonc (v0.3.4), tailscale/hujson | Default | Default | |
Python | json-with-comments (1.3.0) | Default | Default |
Java | Jackson | Optional | Optional |
Kotlin | kotlinx.serialization.json | Optional | Optional |
| nlohmann/json, RapidJSON | Optional | Optional | |
| glaze | Default through its JSONC reader | Unsupported | |
otar/jsonc | Default | Default | |
steelbrain/JSONCKit | Default | Default |
One packaging detail affects JavaScript users. jsonc-parser 3.3.1 works with require, as in the samples here. The 4.0.0 prereleases are published as ES modules only, so load them with import.
The list also names a C library (CAJ) and an Elixir one. Read the options before you rely on any of them: "JSONC support" ranges from a strict match of the draft to a parser with extensions of its own. For the other side, see the list of JSON5 implementations and the conformance results.
Converting in Each Direction
JSONC to JSON5
Usually no rewrite is needed. Parse the file once with JSON5.parse to prove it, change the extension, and update whatever loads it. Comments stay exactly where they were, because you did not regenerate the text. Only rewrite if you also want JSON5 style, knowing that serializing drops comments:
const value = readJsonc('{ "a": 1, // x\n "b": [2,], }');
console.log(JSON5.stringify(value, null, 2));
// {
// a: 1,
// b: [
// 2,
// ],
// }JSON5 to JSONC or JSON
Parse as JSON5 and write with JSON.stringify. Strict JSON output is valid JSONC. Beware that JSON.stringify turns Infinity and NaN into null without a word, so stop the conversion instead:
const src = "{ name: 'api', port: 0x1F90, ratio: .5, limit: Infinity }";
const finiteOnly = (key, v) => {
if (typeof v === 'number' && !Number.isFinite(v)) {
throw new RangeError(`key "${key}" is ${v}; JSONC cannot hold it`);
}
return v;
};
JSON.stringify(JSON5.parse(src), finiteOnly, 2);
// RangeError: key "limit" is Infinity; JSONC cannot hold itThis route discards every comment. If the comments carry meaning, move them by hand while the diff is open, or keep the file in JSON5 and generate JSON as a build artifact. More options are on the conversion tools page.
Editing JSONC without losing comments
jsonc-parser has a feature the json5 package does not: it computes text edits, so one value changes and the rest of the file is untouched.
let doc = '{\n // keep me\n "port": 80,\n}\n';
const edits = jsonc.modify(doc, ['port'], 8080, {
formattingOptions: { insertSpaces: true, tabSize: 2, eol: '\n' }
});
console.log(jsonc.applyEdits(doc, edits));
// {
// // keep me
// "port": 8080,
// }The package also exports stripComments. It removes comments only: trailing commas remain, so the result is not guaranteed to be JSON.
Which to Choose
Start with one question: who parses the file? If the answer is a tool you did not write, its documentation decides, and your preference does not.
| Situation | Choose | Reason |
|---|---|---|
| VS Code, TypeScript, dev containers, Wrangler, Deno | JSONC | It is what they document |
A tool that documents .json5 support | JSON5 | Fuller syntax with one specified behavior |
| Your own application's hand-written config | JSON5 | Strict, throwing parser; no option flags to agree on |
| A program must edit the file and keep comments | JSONC | modify and applyEdits |
Values include Infinity, NaN or hex | JSON5 | JSONC cannot express them |
| People unfamiliar with JavaScript syntax | JSONC | Looks like JSON with notes |
| Data exchanged between programs or over an API | Neither; use JSON | Every consumer can read it |
There is also a third design, JSON With Commas and Comments, covered in the JWCC comparison. For the wider field, including YAML and TOML, use the main comparison, the YAML comparison or the TOML comparison.
Related Questions
New to the topic? Comments in JSON explains why JSON has none and lists every option in one table. Choosing a library and not a format? npm packages compared runs the same inputs through json5, jsonc-parser, comment-json, strip-json-comments and hjson. For the most common case of all, see comments in package.json.
Common Questions
Is JSONC the same as JSON5?
No. JSONC adds comments to JSON, with optional trailing commas. JSON5 adds those and also unquoted keys, single-quoted strings, more number forms, line continuations and more whitespace characters.
Does JSON.parse read JSONC?
No. A comment or trailing comma throws a SyntaxError. Use a JSONC parser, or a JSON5 parser if you accept that it also allows much more than JSONC does.
Can I parse JSONC with a JSON5 library?
Yes for practically all files. Two caveats: it will not reject JSON5-only syntax that other JSONC tools reject, and a raw U+2028 or U+2029 inside a line comment is read differently.
Is JSONC an official standard?
No. jsonc.org publishes a community draft that formalizes the default behavior of Microsoft's parser. Its recommended media type was not in the IANA registry when checked.
Why does my editor warn about a trailing comma?
VS Code accepts trailing commas in JSON with Comments mode but flags them unless the file's schema allows them. Prettier's json parser also removes them.
Should I rename my .json files to .jsonc?
Only if the tool that loads them looks for the new name. Tools with fixed names such as tsconfig.json expect those names; add a mode line or an editor association instead.
Sources
(23)
- JSONC Specification (draft), jsonc.org
- JSONC ABNF grammar
- JSONC specification repository history
- JSONC Tools and Libraries list
- The JSON5 Data Interchange Format 1.0.0
- json5/json5 repository README
- microsoft/node-jsonc-parser
- jsonc-parser on npm
- node-jsonc-parser pull request 140: __proto__ properties
- npm download counts API
- IANA Media Types registry
- VS Code documentation: Editing JSON
- VS Code JSON extension language declarations
- VS Code configuration-editing language declarations
- VS Code TypeScript language declarations
- eslint/json README
- Babel documentation: Configuration Files
- Development Container reference
- Cloudflare Wrangler configuration
- Deno configuration documentation
- Turborepo configuration reference
- Biome: Configure Biome
- Renovate configuration options
Last reviewed: November 29, 2026.
JavaScript
Python
TypeScript
Node.js
Rust
Java
C#
Ruby
Kotlin
Lua
Babel
Vite
webpack
ESLint
Prettier
VS Code
JetBrains 