JSON5 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.

Two config documents on a lit workbench, one labeled JSONC and one labeled JSON5, with a parser checking each line

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.

Visual Studio Code logo

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.

QuestionJSONCJSON5
Written specificationDraft at jsonc.orgVersion 1.0.0, March 2018
BaseJSON grammar (RFC 8259 rule names) plus commentsJSON plus ECMAScript 5.1 syntax
Comments// and /* */// and /* */
Trailing commasParsers MAY support them; not in the grammarRequired of every parser
Recommended extension.jsonc.json5 by convention
Reference JavaScript parserjsonc-parser 3.3.1 (June 2024)json5 2.2.3 (December 2022)
npm downloads, November 22-28, 2026107,185,119303,643,299

Download counts measure installs, including indirect ones through build tools. They do not show how many people write either format.

Document icon

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."

Compare icon

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.

InputJSON5JSONC defaultJSONC with trailing commas
// and /* */ commentsAcceptedAcceptedAccepted
{ "a": 1, }AcceptedErrorsAccepted
[1, 2,]AcceptedErrorsAccepted
[1,,2]RejectedErrorsErrors
[,]RejectedErrorsErrors
{ a: 1 }AcceptedErrors, value {}Errors, value {}
{ "a": 'x' }AcceptedErrors, value {}Errors, value {}
0xFF255Errors, value 0Errors, value 0
.50.5ErrorsErrors
5.5ErrorsErrors
+11ErrorsErrors
Infinity, NaNAcceptedErrorsErrors
012RejectedErrors, value 0Errors, value 0
Backslash at end of line inside a stringLines joinedErrorsErrors
"\x41""A"Errors, value "41"Errors, value "41"
\', \v or \0 escapes in a stringAcceptedErrorsErrors
Raw tab inside a stringAcceptedErrorsErrors
Form feed or non-breaking space between tokensAcceptedErrorsErrors
Byte order mark at the startAcceptedErrorsErrors
# commentRejectedErrorsErrors
Unterminated /* after the valueRejectedErrorsErrors
Empty file, or only a commentRejectedErrors, undefined (silent with allowEmptyContent)Same
{} {}RejectedErrorsErrors
Missing comma between membersRejectedErrorsErrors
Duplicate keyLast wins, silentlyLast wins, silentlyLast wins, silently
9007199254740993900719925474099290071992547409929007199254740992

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' ]
Warning icon

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 exception

For 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 7

The 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.

Layers icon

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.

List icon

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 ruleTrailing comma behaviorBasis
jsonc.org draftParsers MAY accept; the ABNF excludes themSpecification
jsonc-parserError unless allowTrailingComma: trueTested
Visual Studio Code logoVS Code "JSON with Comments" modeAccepted, with a warningVS Code documentation
VS Code's own config filesAccepted without a warning, because their schemas allow itjsonc.org appendix
TypeScript logotsc 5.9.3 and 7.0.2 on a tsconfigAcceptedTested
Prettier logoPrettier 3.10.1, tsconfig.json and settings.jsonParser inferred as json; commas removed, comments keptTested with default options
Prettier logoPrettier 3.10.1, .jsonc and .json5Commas added on multi-line lists and objects; in .json5 files, quotes also removed from simple keysTested with default options
ESLint logo@eslint/json, json/jsonc languageOpt in with languageOptions.allowTrailingCommasPackage README
Deno, deno.jsoncComments and trailing commas allowedDeno documentation
npm logopackage.jsonStrict JSON: no commas, no commentsTested 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.

TypeScript logo

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 contentBoth compiler versions
Comments and trailing commasNo diagnostics
Single-quoted key and stringTS1327: String literal with double quotes expected.
Unquoted keyTS1327: String literal with double quotes expected.
"maxNodeModuleJsDepth": 0x2No 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.

Globe icon

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:

GroupNames and extensions
Editor configurationsettings.json, launch.json, tasks.json, keybindings.json, extensions.json, mcp.json, argv.json, profiles.json, .code-workspace
TypeScript and JavaScript projectstsconfig.json, jsconfig.json and variants such as tsconfig.*.json
Dev containersdevcontainer.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

ProjectWhat its documentation says
Development Container specificationMetadata can be stored in a JSON with Comments file called devcontainer.json
Cloudflare WranglerRecommends wrangler.jsonc for new projects; JSON and JSONC configs since 3.91.0
DenoDetects deno.json or deno.jsonc
TurborepoSupports turbo.jsonc
BiomeConfig file is biome.json or biome.jsonc
RenovateAccepts both; recommends a .jsonc file over .json5 if you want comments, and warns that its config migration can downgrade JSON5 content
JSON5 reference projectNames 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.

Plugin icon

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:

LanguageLibraryCommentsTrailing commas
JavaScript logoJavaScriptmicrosoft/node-jsonc-parser (3.3.1)DefaultOptional
Rust logoRustdprint/jsonc-parser (crate 0.34.0)DefaultDefault
Go logoGotidwall/jsonc (v0.3.4), tailscale/hujsonDefaultDefault
Python logoPythonjson-with-comments (1.3.0)DefaultDefault
Java logoJavaJacksonOptionalOptional
Kotlin logoKotlinkotlinx.serialization.jsonOptionalOptional
C++ logoC++nlohmann/json, RapidJSONOptionalOptional
C++ logoC++glazeDefault through its JSONC readerUnsupported
PHP logoPHPotar/jsoncDefaultDefault
Swift logoSwiftsteelbrain/JSONCKitDefaultDefault

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.

Convert icon

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 it

This 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.

Target icon

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.

SituationChooseReason
VS Code, TypeScript, dev containers, Wrangler, DenoJSONCIt is what they document
A tool that documents .json5 supportJSON5Fuller syntax with one specified behavior
Your own application's hand-written configJSON5Strict, throwing parser; no option flags to agree on
A program must edit the file and keep commentsJSONCmodify and applyEdits
Values include Infinity, NaN or hexJSON5JSONC cannot express them
People unfamiliar with JavaScript syntaxJSONCLooks like JSON with notes
Data exchanged between programs or over an APINeither; use JSONEvery 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.