{}JSON FYI

JSON comments — why they don't exist and what to do instead

JSON has no comment syntax. Here are five practical workarounds, ranked.

·5 min read

Douglas Crockford removed comments from JSON deliberately so people wouldn't put parse directives in them. As a result, // and /* */ are syntax errors.

Workarounds, ranked

  • Sibling fields: add a "_comment" key next to the value. Easy, survives round-trips, but adds noise.
  • JSONC: a comment-tolerant superset used by VS Code's settings. Requires a JSONC parser to read.
  • JSON5: comments + trailing commas + unquoted keys. Great for human-edited config; requires a JSON5 parser.
  • YAML or TOML: switch formats if comments matter a lot.
  • Strip before parsing: a regex pre-pass that removes comments. Fragile — strings can contain ", //, " and trip you up.

Frequently asked questions

Will adding a _comment key break my schema?+

It can if the schema uses additionalProperties: false. Either allow it explicitly or strip _comment before validation.

Related tools & guides