I sometimes use Visual Studio Code to edit JSON files that include comments. VS Code displays an error saying, "Comments are not permitted in JSON." It would be nice to disable that error message (without having to remove the comments.)
4 Answers
Follow these steps:
- Click on the letters JSON in the bottom right corner. (A drop-down will appear to "Select the Language Mode.")
- Select "Configure File Association for '.json'..."
- Type
jsonc
and press Enter.
If you only want to disable the error message for a single file, skip step #2.
-
10If you want to use the Command Palette or assign a keyboard shortcut, this is called "Change Language Mode" Commented Jan 24, 2018 at 23:18
-
1is it possible to config this via comment at the beginning of a file? just like control comments of jslint.– 牛さんCommented Jan 29, 2018 at 8:28
-
@Wayou No, you can't configure that with a comment. At least, not that I know of in VSCode. Commented Feb 3, 2018 at 9:04
-
1In User Settings, you can default all .json files to JSON with Comments: stackoverflow.com/a/48773989/4642023 Commented Feb 13, 2018 at 19:14
-
Add this to your User Settings:
"files.associations": {
"*.json": "jsonc"
},
If you don't already have a user settings file, you can create one. Hit Ctrl+, or ⌘+, (that's a comma) to open your settings, then hit the Open Settings (JSON) button in the upper right. It looks like this:
-
6Found this useful, but I also agree with v-andrew - usually want to keep the jsonc separate from the normal json files. Where I found this useful though is vendor supplied files - like
rush.json
which the vendor supplies with comments. In that case use a file association like:"files.associations": { "rush.json": "jsonc" }
no need to wildcard it.– ChrisCommented Dec 29, 2020 at 14:38
Just rename file to test.jsonc
Reasons to use JSONC
and not to allow comments in the regular JSON
files are:
- It will separate your file from real JSON files
- It is not going to bite you in the back when you add comment to a file where validation has to be applied, but you forget to remove comments because there is no error message.
- It is going to work out of the box on any setup without "tuning" someone's else VS Code.
answer: enter associations
in VScode setting, add item *.json
jsonc
.
btw: What is your screenshot software? pleassssse tell me, and which font on screenshot img?
-
I think your answer is probably a dupe of this answer... I'm guessing you posted so you could ask the question even though you don't have enough rep for a comment? I'll go ask and maybe you can delete this?– ruffinCommented Jun 12, 2022 at 1:56
;)
).