Put comments in JSON file in Visual Studio 2015


I am experimenting with the new Visual Studio and I see that in the new project structure and in the configuration the files JSON is used intensively, to the detriment of the XML that was used before in web.config , etc.

The fact is that I would like to leave commented some dependencies in the file config.json and I find that, using // to comment a line, the syntax coloring acts correctly, but the compiler does not swallow it.

Is there any special syntax for these types of comments at least in the configuration files?

asked by Vi100 09.12.2015 в 12:11

4 answers


The syntax coloring marks it, but when doing build it clearly detects the error (see image below).

My recommendation in this particular case, where you want to disable the dependency temporarily , is to create a new section in the configuration file, example here I am moving the Azure Storage reference to this section, whenever you want return it to move it to the correct section.

"dependencies": {
    "EntityFramework.Commands": "7.0.0-rc1-final",
    "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final",
    "Microsoft.AspNet.Authentication.Cookies": "1.0.0-rc1-final",
    "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-rc1-final"
"commentedDependencies": {
    "WindowsAzure.Storage": "6.1.0"

This avoids changing the name of the dependency, because then the engine will look for a dependency that will not be resolved and can be given for other errors.

answered by 09.12.2015 / 13:25

The problem is that JSON is not JavaScript (see www.json.org , rfc4627 , rfc7159 and the following suggestion) and therefore is not recognized when parsearlo.

The suggested typical solution ( see ) is usually add a comment type property such as:

"__comment": "bla, bla, ..."
answered by 09.12.2015 в 12:24

You can specify several values with the same key but the last one has priority over the previous one, knowing this you can use the following but I do not know if this will be the best way, but maybe it will help you

  "numeros": "esto es un comentario",
  "numeros": [1, 2, 3]
answered by 09.12.2015 в 12:32

If you want to disable a certain key from a configuration file without deleting it, simply change the name; the engine will ignore any unknown key (and presumably your code will also do it, if you use custom configuration files). A good convention is, as suggested by josejuan, to add an underscore ("_") to the beginning of the name; In this way you see at a glance which keys are "commented".

answered by 09.12.2015 в 12:42