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
{
// This is the user's name
"name": "John",
/* Age in years */
"age": 30,
"active": true // currently active
}{
"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?
How can I add comments to a config file?
Will a JSON parser just ignore my comments?
Check Your JSON Now
Our JSON validator detects this error automatically and shows the exact line and column.
Open JSON ValidatorCloudways · 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
Related JSON Errors
Unexpected Token in JSON
Fix the unexpected token error in JSON fast. See why parsers fail on trailing commas, single quotes, unquoted keys, and comments, with clear examples.
Single Quotes in JSON
JSON requires straight double quotes for every string and key, so single quotes always break parsing. Learn how to fix the single quotes error fast.
Trailing Comma in JSON
Fix the trailing comma error in JSON quickly. Unlike JavaScript, JSON forbids a comma after the last element, and our examples show you exactly how.