JSON5 Comments in JSON: What Works and What Breaks

No. Standard JSON has no comments, and a parser that follows the standard rejects the first slash it sees.

You still have real options: a superset such as JSONC or JSON5, a different format such as YAML, a workaround key like "//", or a step that strips comments before parsing. Which one is right depends on which program reads the file.

We ran one commented sample through JSON.parse, jsonc-parser and json5 and pasted the real output below, so you can see what each one does with it.

A JSON file with a handwritten note beside it being refused by a strict parser while a commented copy passes

TL;DR: JSON cannot have comments; JSON.parse throws on them. If a tool you do not control reads the file, use whatever that tool documents (JSONC for VS Code settings and tsconfig.json, plain JSON with no comments for package.json). If you control the reader, JSON5 or JSONC gives real comments. If you only need a note in strict JSON, a "//" key works, with limits shown below.

Question icon

The Short Answer

No. The JSON grammar in RFC 8259 defines whitespace as four characters (space, tab, line feed, carriage return) and has no comment syntax. The grammar on json.org says only that "Whitespace can be inserted between any pair of tokens" and likewise defines no comment. A parser that follows the standard has to reject a file with a // or /* */ in it.

RFC 8259 does allow a parser to accept "non-JSON forms or extensions" (section 9). That permission is why some tools read comments and others do not. The file is still not JSON, and nothing guarantees that the next program you hand it to will accept it. That one fact explains most of the confusion on this topic: the same .json file works in one program and breaks in another.

Strict JSON also does not give you duplicate keys as a safe fallback. RFC 8259 says "The names within an object SHOULD be unique" and that when they are not, "the behavior of software that receives such an object is unpredictable." We show a real duplicate-key result further down.

History icon

Why JSON Has No Comments

It was removed on purpose. Douglas Crockford, who specified JSON, wrote a Google+ post in April 2012 that is widely quoted as: "I removed comments from JSON because I saw people were using them to hold parsing directives, a practice which would have destroyed interoperability." The idea was that a comment carrying an instruction for one parser would make files mean different things to different programs.

Source note. The original post lived at plus.google.com/118095276221607585885/posts/RK8qyGVaGSr, and Google+ is gone. We could not open an archived copy of it, so we are quoting it as widely quoted. The best copy we opened is the Hacker News thread of 04-30-2012, titled "Douglas Crockford: Why I removed comments from JSON". A commenter there quotes the sentence above and links to the Google+ post. The same thread paraphrases his advice for annotated config files: write the comments you like, then strip them before handing the file to a JSON parser.

The people who wanted comments back did not wait. The JSON5 project started in 2012 as a parser built on Crockford's own json_parse.js with comments added; its story is on the history page, and the trade-offs of that choice are on the design rationale page. For how to write comments that stay useful, read comments best practices.

Compare icon

Every Real Option in One Table

"Reads it natively" means a mainstream program opens the file with no plugin and no pre-processing. We tested the entries marked "tested" on 12-01-2026; the rest cite a source in the references.

Option Comment syntax Reads it natively What breaks
JSONC // and /* */ VS Code settings files (VS Code docs); tsconfig.json (tested with TypeScript 7.0.2: comment and trailing comma accepted) JSON.parse and every strict parser. Trailing commas are a per-tool choice: jsonc-parser reports them as errors unless you pass allowTrailingComma
JSON5 // and /* */ (spec section 7) Babel, Renovate, pnpm manifests and others; see the config guides Strict parsers, and every editor or tool that expects JSON or JSONC. Unquoted keys and single quotes are not JSONC (tested: jsonc-parser reported errors and returned an empty object)
Hjson #, // and /* */ (hjson.github.io) Libraries only; we did not test any editor or build tool that reads it natively Everything that is not an Hjson library. Parsed our commented sample with hjson 3.2.2 (tested)
YAML # (YAML 1.2.2, section 6.6) Kubernetes manifests, CI workflows and compose files, by convention of those tools It is a different language. You rewrite the file and drop the braces; indentation now matters. Parsed a commented sample with yaml 2.9.1 (tested)
"//" key A normal key whose value is the note Any JSON reader, because it is valid JSON The note is data. Repeating the key keeps only the last value (tested). In some places the key is read as something else: see package.json
"_comment" key Same idea with another name Any JSON reader Same limits as "//"; a schema that forbids unknown keys will reject it, so check yours
Strip, then parse Whatever the stripper accepts, usually // and /* */ Your own code, with strip-json-comments or similar Other programs still see a file with comments. Works only where you own the loading code (tested with strip-json-comments 5.1.0)

Side-by-side detail on each format is on the JSONC, Hjson and YAML comparison pages. The JSONC rules are written up at jsonc.org: it recommends the .jsonc extension and says parsers "MAY support trailing commas".

Test icon

Tested: The Same Sample in Three Parsers

Run on 12-01-2026 with Node.js 24.22.1, json5 2.2.3, jsonc-parser 3.3.1 and strip-json-comments 5.1.0, all installed from npm into an empty folder. The sample:

{ // port the server listens on "port": 8080, /* keep in sync with the proxy */ "host": "localhost" }
Parser Real result
JSON.parse(text)Throws SyntaxError: Expected property name or '}' in JSON at position 4 (line 2 column 3)
jsonc-parser parse(text, errors){"port":8080,"host":"localhost"} with an empty errors array
json5 parse(text){"port":8080,"host":"localhost"}
JSON.parse(stripJsonComments(text)){"port":8080,"host":"localhost"}

The error position is the point to remember: JSON.parse fails at the first comment, position 4, and says nothing about comments. Developers often read "Expected property name" as a broken key, not as a comment. If you see it on a file you edited by hand, look for a comment or a trailing comma first.

Where JSONC and the other formats part ways

Two more results from the same run. A trailing comma after the last member ({ "a": 1, }) parsed to {"a":1} in jsonc-parser but came with two errors (codes 3 and 4 at offset 16) until we passed {allowTrailingComma: true}, which cleared them. And json5 rejected a # comment with the message JSON5: invalid character '#' at 1:1, because # is Hjson and YAML syntax, not JavaScript syntax.

The duplicate-key "//" sample

A common tip is to write several "//" keys in one object. Valid JSON, but only one survives:

{ "//": "first note", "//": "second note", "port": 8080 }

JSON.stringify(JSON.parse(text)) in Node.js 24.22.1 printed:

{"//":"second note","port":8080}

The first note is gone and no error was raised. RFC 8259 calls this behavior unpredictable across implementations, so do not rely on the last one winning in another language. If you want several notes, make the value an array ("//": ["one", "two"]) or give each key its own name ("//port").

Target icon

Which One Should You Use?

Ask who reads the file. The answer is almost always set by the reader, not by your taste.

Decision diagram titled Comments in JSON: Who Reads the File? VS Code settings and tsconfig.json use JSONC, package.json uses a // key, your own program uses JSON5 or JSONC, an API uses strict JSON, a one-off file is stripped then parsed
Who reads the file Use Why
VS Code settings, tsconfig.jsonJSONC, in the same fileBoth accept comments as shown above. Do not rename the file. See tsconfig.json and JSON5
package.json (npm, Yarn, pnpm)A "//" key, or a READMEThe package managers we tested reject // comments. See comments in package.json
A tool that documents JSON5 supportJSON5The tool already ships the parser. Check its guide under config files
Your own programJSON5 or JSONC, plus a parser you installYou choose the reader, so use real comments. Our JavaScript guide covers loading
An API, a database column, another team's codeStrict JSON, with a "//" key only if the schema allows itYou cannot know the parser. Keep the file to the standard
A config file where syntax is your choiceYAML, if the team already uses itNative # comments, but a different language and different mistakes
A one-off file you want to read as JSONStrip, then parsePaste it into the online converter, which strips the comments and gives you plain JSON

Comments do not survive a rewrite. A parser returns data, and data has no comments. If a program reads the file and writes it back, the comments are gone unless that tool preserves them. The preserving comments tutorial covers round-trip parsers.

If you are choosing a format for a new config file and nothing forces your hand, the comparison hub lists every format side by side. The short version: JSONC if you only want comments, JSON5 if you also want unquoted keys and trailing commas guaranteed, YAML if your tooling is already YAML.

Comments in JSON: Common Questions

Can JSON have comments?

Not in the standard. RFC 8259 defines no comment syntax, and JSON.parse in Node.js 24.22.1 threw at the first //. Supersets such as JSONC and JSON5 add them.

What is JSON with comments?

Usually JSONC: JSON plus // and /* */ comments. VS Code uses it for its settings files, and its docs call it a separate mode from plain JSON.

Is JSONC the same as JSON5?

No. JSON5 adds unquoted keys, single quotes and more. In our test jsonc-parser returned an empty object and four errors on an unquoted key. See JSON5 vs JSONC.

Is a "//" key a real comment?

No, it is data that happens to be ignored by most programs. It survives parsing, shows up in output, and repeated keys keep only the last value.

How do I remove comments before parsing?

Run the text through strip-json-comments and then JSON.parse. It worked on our sample. The online converter does it in the browser.

Can package.json have comments?

Not with // in npm, pnpm or Yarn as we tested. Bun read them. See comments in package.json for the exact output.

Need the Comments Gone?

Paste a commented file into the converter and get plain JSON back, in your browser.

Open the Converter

Sources

(11)
  1. RFC 8259: The JSON Data Interchange Format (sections 2, 4 and 9)
  2. json.org: Introducing JSON (grammar and whitespace)
  3. Hacker News, 04-30-2012: "Douglas Crockford: Why I removed comments from JSON" (the quote and a link to the original Google+ post, which we could not open)
  4. The JSON5 specification, section 7: Comments
  5. JSONC specification
  6. Visual Studio Code: Editing JSON with Visual Studio Code (JSON with Comments mode)
  7. Hjson, a user interface for JSON
  8. YAML Specification 1.2.2 (section 6.6: Comments)
  9. jsonc-parser on npm (3.3.1 tested)
  10. strip-json-comments on npm (5.1.0 tested)
  11. json5 on npm (2.2.3 tested)

Last reviewed: December 1, 2026.