Comments on JSON in Visual Studio

Asked

Viewed 545 times

2

JSON does not support comments, but in Visual Studio (2017 to be more specific, my version) I add comments and do not present any error, but when I open the file in Visual Studio Code, the following message is presented to me: Comments are not permitted in JSON.

Can anyone explain that to me?

  • 3

    In Vscode it is also possible to use comments in JSON. I believe there must be something native to each particular system that Minifyca(compiles/decompiles) JSON when you save/open the file. Take a look at this link that has an interesting video. https://www.oreilly.com/learning/adding-comments-in-json no Stackoverflow gringo tb has a lot on the subject https://stackoverflow.com/questions/2477/can-comments-be-used-in-json and this is the Vscode project on Github https://github.com/Microsoft/vscode

  • @hugocsl saw that at the end of the video the author puts a cool question in <title>, Can you use comments in json? I think this deserves a better discussion since it’s an arrangement!

2 answers

1

The standard VS Code JSON parser does not support comments, but it does have another available that supports.

You can simply choose this other parser, for a particular file, through the following steps:

  1. Click the status bar on the item indicating the file format JSON.
  2. Choose the parser JSON with Comments (jsonc)
  3. Ready

Or else, you can set up VS Code to always use this parser when opening a file .json. For this, follow the following steps:

  1. Click the status bar on the item indicating the file format JSON.
  2. Choose the option Configure File Association for ‘.json’...
  3. Choose the parser JSON with Comments
  4. Ready

From that moment on, every time you open a file .json, will be used the parser that supports comments.

0

In JSON, if you include a comment it will also be a given;

In your JSON file, you could create a comment from that form;

"_comentario" : "seu comentario",

And you can ignore the value when using in your application;

Because it was defined from that form by Standard ECMA - 404, 2nd Edition - December - 2017,

That a JSON object starts with the opening "{" key and ends with the closing "}" key. Each name is followed by : (two points) and the name/value pairs are followed by , (comma).

See more information in the link below:

https://www.json.org/json-pt

Browser other questions tagged

You are not signed in. Login or sign up in order to post.