In VS Code, disable error "Comments are not permitted in JSON"

JsonVisual Studio-CodeComments

Json Problem Overview


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.)

enter image description here

Json Solutions


Solution 1 - Json

Follow these steps:

  1. Click on the letters JSON in the bottom right corner. (A drop-down will appear to "Select the Language Mode.")
  2. Select "Configure File Association for '.json'..."

enter image description here

  1. Type jsonc and press Enter.

enter image description here

If you only want to disable the error message for a single file, skip step #2.

Solution 2 - Json

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: the button's icon; a page with a little curved arrow over it

Solution 3 - Json

Just rename file to test.jsonc

Reasons to use JSONC and not to allow comments in the regular JSON files are:

  1. It will separate your file from real JSON files
  2. 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.
  3. It is going to work out of the box on any setup without "tuning" someone's else VS Code.

Solution 4 - Json

enter json config demo in this picture

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?

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionWallace KellyView Question on Stackoverflow
Solution 1 - JsonWallace KellyView Answer on Stackoverflow
Solution 2 - JsonJoe MaffeiView Answer on Stackoverflow
Solution 3 - Jsonv-andrewView Answer on Stackoverflow
Solution 4 - JsonjsassView Answer on Stackoverflow