Wallace
Wallace

Reputation: 17379

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

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

Upvotes: 247

Views: 86813

Answers (4)

jsass
jsass

Reputation: 19

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?

Upvotes: -3

v-andrew
v-andrew

Reputation: 24191

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.

Upvotes: 37

Joe Maffei
Joe Maffei

Reputation: 1993

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

Upvotes: 125

Wallace
Wallace

Reputation: 17379

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.

Upvotes: 449

Related Questions