JSON Styles Broken on v7.9.1
-
I just installed 7.9.1 (brand new install on a brand new installation of Windows 10) and found that the styles for JSON files are eye-searingly broken. Is this a known issue? Is there a fix?
-
The JSON parser, inherited from the Scintilla library, despite claiming to support LINECOMMENT and BLOCKCOMMENT styles, interprets comments as errors, so applies the ERROR style to such text.
Your choices are
- ask and wait for Scintilla to fix that bug, then ask and wait for Notepad++ to upgrade its internal Scintilla version.
- workaround: using the PythonScript plugin, you can add extra highlighting to a builtin lexer (like the JSON lexer) using regexes via the script
EnhanceAnyLexer.py
that @Ekopalypse shares in his github repo . So you could use a regex like//.*$
and apply some other style values. - change the ERROR styling to be similar to the comment style – maybe use a slightly different color, so if the line really is an error, you will still see it.
-
@Clonkex ,
Actually, this sounded like a familiar question, so I searched for “JSON comment” in this forum, and found this earlier discussion.
If you use PythonScript, you can use
editor.setProperty("lexer.json.allow.comments",1)
in your startup.py to always enable JSON comments, those comments will properly highlight:becomes
AFAIK, no one followed my advice of submitting a feature request to have Notepad++ provide that option. If you do put in that feature request (I even gave potential text for the request in that other topic), if you could link the issue you create both in this topic and that one, that way future readers can see how it progressed.
-
Just to add to that, JSON by design does not have comments. It is a data only file type. Some if not most parsers error upon finding comments, so I guess Notepad++ is right here.
See also https://stackoverflow.com/questions/244777/can-comments-be-used-in-json