Search code examples
jsoncommentswebstorm

Why can I put comments in some JSON files but not others?


My IDE (WebStorm) lets me put comments in some of my JSON files (e.g., tsconfig.json and .eslintrc.json, but balks at allowing them in others (e.g., package.json and app.json).

The former are subsequently identified as "JSON with Comments" on GitHub (even if I don't actually have comments in them).

Why can I put comments in some JSON files but not others?


Solution

  • By default the IDE checks for strict standard compliance, as standard JSON doesn't allow comments.

    We have a set of options to relax compliance checking in Settings | Editor | Inspections, JSON and JSON5 | Compliance with JSON standard, and for some files the option for checking comments is off by default (tsconfig, tslint and eslint configs), as corresponding tools allow comments in JSON (this is hardcoded).

    If you need adding comments to certain JSON files, you can add their names to the list of patterns associated with JSON5 file type in Settings | Editor | File Types - JSON5 standard allows comments