</>
ValidateHTML

Comments in JSON

JSON does not support any form of comments. Neither // single-line comments nor /* multi-line comments */ are valid. This was a deliberate design choice by Douglas Crockford to keep JSON simple and prevent abuse of comments for parsing directives.

Why It Matters

Adding comments to JSON makes it unparseable by any standard JSON parser. This is a common issue with configuration files where developers want to document settings inline.

Common Causes

  • Documenting a config file inline with // or /* */, expecting a strict JSON parser to ignore them.
  • Copying a JSONC or JSON5 snippet, which permits comments, into a file parsed as plain JSON.
  • Leaving a commented-out property in place while debugging, then parsing the file as standard JSON.

Code Examples

Invalid JSON
{
  // This is the user's name
  "name": "John",
  /* Age in years */
  "age": 30,
  "active": true // currently active
}
Valid JSON
{
  "name": "John",
  "age": 30,
  "active": true,
  "_comment_active": "Whether the user is currently active"
}

How to Fix

  • 1Remove all // and /* */ comments from your JSON files.
  • 2Use a _comment or __note key if you need inline documentation.
  • 3Consider using JSONC (JSON with Comments) format for config files. VS Code and TypeScript support it.
  • 4For configuration files, consider YAML or TOML which natively support comments.

Frequently Asked Questions

Why does JSON not allow comments?
Douglas Crockford removed comments deliberately to keep JSON a pure data format. He worried people would embed parsing directives in comments, breaking interoperability. RFC 8259 defines no comment syntax, so any parser rejects them.
How can I add comments to a config file?
Use JSONC (JSON with Comments) or JSON5, supported by VS Code settings and tsconfig.json. For plain JSON, add a dummy key like "_comment" with a string value, or switch the file to YAML or TOML.
Will a JSON parser just ignore my comments?
No. A standard parser treats // or /* as an unexpected token and fails the whole document. Only parsers that explicitly support JSONC or JSON5 strip comments before parsing.

Check Your JSON Now

Our JSON validator detects this error automatically and shows the exact line and column.

Open JSON Validator
Recommended

Cloudways · Managed Cloud Hosting

Fix this JSON error, then deploy on Cloudways managed cloud (AWS, GCP, DigitalOcean).

Free 3-day trial · 30% off 3 months + free site migration with code MIGRATE303

Start free trial

Related JSON Errors

View all JSON errors