# Comments in JSON Files
My company uses JSON for configuration files, but we allow comments in them delimited with hash signs (#). WebStorm handles this spectacularly badly. Other tools, like VS Code handle this correctly, and without any configuration.
Is there a way to turn this on in WebStorm? I've looked and I don't see anything.
请先登录再写评论。
This is not a valid JSON, and there is no way to make webstorm accept it, sorry.
WebStorm allows using javascriot comments (both block and line), though shows a warning about standard violation; but it doesn't support using `#`
Thanks for verifying for me.
Wish I was enough of the right kind of programmer to build a plug-in for this.
If developing a plugin is not an option, the only solution is turning syntax highlighting off for such files... This can be done using Hector icon in the lower right corner: open your file in editor, click the Hector icon and then move the slider to change the Highlighting level to None. See https://www.jetbrains.com/help/webstorm/2017.3/changing-highlighting-level-for-the-current-file.html. You will likely need to reopen the project to get the highlighting updated.
It's not the highlighting that's the problem. That's actually the only part that works and the reason why I don't just leave *.conf mapped to plain text files. What I'm seeing is:
Pasting in a multi-line object that is indented correctly causes all properties and subobjects to line up a position 0, flush left. The first and sometimes second lines do not, but they are not usually lined up correctly. This also happens with "Format Code", but for the whole file, plus is puts comments that don't start at pos 0 as one character per line.
Because you can't do a format code to get all the indenting correct, it seems like it auto-format-as-you-type to put new lines starting at the wrong column. It uses the configured option, which I have at 2, but if the file is formatted at 3 or 4 character indents, it's a pain to get everything lined up so you can easily eyeball what is a child of who. Sometimes, it puts the starting place as too far right, and you have to move to where you want it indented and delete characters, because if you put the cursor at the start of the characters and hit backspace it move everything up the previous line. That's supposed to happen, but the fact that it gets the starting column wrong makes it get in the way of fixing things.
Double clicking on a word in a string value, or property name cause the entire file to be selected. This doesn't always happen, but usually happens, I haven't figured out what the pattern is.
These things happen on both computer I have installed. These are minor complains compared to all the other stuff WebStorm does for me. But our tools are supposed to work for us, not against us like this.
Is there an enhancement request process?
To me, using `#` as line comments in JSON causes syntax errors, so the highlighting is broken (and formatting as well, of course, as it's based on a syntax tree built by lexer, and, if file can't be parsed correctly, formatting is a mess).. Might be a misunderstanding. what does you syntax look like? please provide JSON files that can be used to recreate the issues
Visual Studio Code supports JSONC (JSON with Comments).
I think that it could be useful that PHPStorm can support in the future the same format described at:
https://komkom.github.io/
The reason why to have a JSON file commented is because sometimes small JSON files are used as configuration files or templates and to have comments in those files will provide some explanations about what means each key/node.
Since 2018.2, Webstorm supports JSON5 standard that alows comments. See https://blog.jetbrains.com/webstorm/2018/05/webstorm-2018-2-eap/, JSON support improvements
Addendum: it is correct that VS code supports the "jsonc" format, but unfortunately it defines comments as "//". So VS code rejects # comments.