219

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

dreftymac
  • 31,404
  • 26
  • 119
  • 182
Wallace Kelly
  • 15,565
  • 8
  • 50
  • 71
  • Fwiw, it [looks like @jass wants to know what app you used for your screenshot](https://stackoverflow.com/a/67292768/1028230) -- asking b/c they don't have enough rep to leave a comment, which I think might be why they duped an answer and posted. (Perhaps not technically a legit comment, but I've seen worse. `;)`). – ruffin Jun 12 '22 at 01:58

4 Answers4

406

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.

Wallace Kelly
  • 15,565
  • 8
  • 50
  • 71
113

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

doppelgreener
  • 4,809
  • 10
  • 46
  • 63
Joe Maffei
  • 1,855
  • 1
  • 15
  • 18
  • 6
    Found 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. – Chris Dec 29 '20 at 14:38
35

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.
v-andrew
  • 21,939
  • 6
  • 36
  • 41
-3

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?

ruffin
  • 16,507
  • 9
  • 88
  • 138
jsass
  • 19
  • 1
  • I think your answer is probably a [dupe of this answer](https://stackoverflow.com/a/48773989/1028230)... 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? – ruffin Jun 12 '22 at 01:56