gotchaMinorpending
JSON does not support comments -- use JSONC or YAML
Viewed 0 times
JSON commentsJSONCJSON5YAMLTOMLparse error
nodejsbrowser
Error Messages
Problem
Adding comments to JSON files causes parse errors. JSON spec does not allow any form of comments. Configuration files in JSON cannot be documented inline.
Solution
Alternatives: (1) JSONC (JSON with Comments): supported by VS Code, TypeScript tsconfig.json, and many tools. Uses // and / /. (2) JSON5: superset with comments, trailing commas, unquoted keys. (3) YAML: supports comments with #. (4) TOML: supports comments with #, great for config. (5) Workaround: use _comment keys in standard JSON (ugly but works).
Why
Douglas Crockford intentionally excluded comments from JSON to prevent parsing directives and keep the format simple. Most configuration use cases outgrew this simplicity.
Revisions (0)
No revisions yet.