When the Language Mode is set to JSON (auto-detects based on file extension), I get the error:
But if I set it to JSON with Comments, the error is gone:
What I want to know is what is happening exactly when I set it to JSON With Comments
:
It's pretty obvious that VSCode stops complaining about comments in JSON files.
But are the comments removed when some package needs to read those files? I usually need to comment inside configuration files like, for example:
Am I risking "corrupting" a configuration file by commenting on it? Is it something safe to do?
In my examples, would eslint
and firebase
ignore the comments? How does it work?
Whether or not comments are supported in a given JSON file is entirely up to how the file will be used. .eslintrc.json
files for example can have comments because the eslint library/tool can parse them properly, however many other tools will complain if they encounter comments in a json
VS Code's two json language modes (JSON
vs JSON with Comments
) only determine how VS Code and its extensions interpret the file in the editor. They do not change the file's content or effect how other applications interpret the file. (i.e. changing modes in VS Code should not "corrupt" the file)
Use the JSON
language mode if you are writing json that needs to be standard json. VS Code will help enforce this by warning if you add a comment or trailing comma
Use the JSON with Comments
language mode if you are writing json for an application that supports comments (like .eslintrc.json
)