JSON5 formatted data cannot be fully collapsed.
-
{ key: 1, name: "更新提示", quickFind: true, matchTime: 10000, actionMaximum: 1, resetMatch: "app", activityIds: [ "net.csdn.csdnplus.activity.MainActivity", "net.csdn.csdnplus.activity.SetActivity", ], rules: [ { matches: "[id=\"net.csdn.csdnplus:id/update\"] -2 [id=\"net.csdn.csdnplus:id/cancel\"]", snapshotUrls: [ "https://i.gkd.li/import/12673693", "https://i.gkd.li/import/12673654", ], }, ], enable: false, }
-
You have showed us your JSON5 data, but you have not explained what you attempted to do, what you expected, or what happened instead. Please tell us.
-
If I am understanding your title correctly, I interpret your problem as meaning “when I try to fold the brace on line 1, it only folds lines 1-11 instead of lines 1-22”.
I can replicate the behavior in my copy.
But I noticed that all the key-value pairs were highlighted in the ERROR style (which appears to be orange background for you; on mine, it’s a pure red background):
If I quote all the keys, instead of leaving them unquoted, the error indicators go away:
and I can fold the whole JSON5 from line 1 to line 22:
When I googled for “does json5 require quotes around the key”, I am informed that JSON5 isn’t supposed to require quotes around the key.
But under the hood, Notepad++ is using the same JSON lexer for both normal JSON and for JSON5 – the difference being that if it’s JSON5, it allows comments.
Notepad++ uses a library called “Lexilla” to implement the lexing (the syntax-highlighting engine, which also handles determining where code folds). When I look at the Lexilla source for the JSON lexer, I don’t _see _ any options in the source code which would allow for changing the behavior of whether or not keys require quotes or not. (But I’ve been known to misunderstand.)
I verified that SciTE (the Scintilla/Lexilla test bed application) also has the same difference in folding, depending on whether or not the keys are quoted.
So, in order for Notepad++ to have the ability to allow JSON5 keys to not be quoted,
- Someone would need to make a request at Scintilla’s Lexilla project for options to allow full JSON5 compliance.
- fortunately for you, someone already has: issue #241
- since it already existed, I will poke at the Lexilla issue.
- Wait for Lexilla to implement it
- Once Lexilla has released a version that includes the unquoted-keys option, then someone (you) would have to put in a feature request with Notepad++ to upgrade Lexilla and add the unquoted-keys option to the
if (isJson5)
handling - Wait for Notepad++ to implement it
And, as a final bit of research results: when the Notepad++ developer added the allow-comments for “JSON5”, he did emphasize here that
Currently, it’s only JSONC (with js comment supported)
And in the Change Log for v8.4.9, the developer said
Add JSON5 support - only JSONC currently (with js comment supported).
He did his best to indicate at the time of release that it’s not fully JSON5-compatible yet, and only allows for JSONC comments, not all the other features of JSON5.
- Someone would need to make a request at Scintilla’s Lexilla project for options to allow full JSON5 compliance.
-
FWIW the JsonTools plugin has full JSON5 support, so you can use its tree view to navigate JSON5 documents.
-
@Mark-Olson I’m trying but it doesn’t seem to work. I have latest of the JsonTools plugin, and latest npp.
It seems to recognize the file as json5 but lists many errors, pretty much the same as posted earlier in this thread.Is there some configuration bit needed for that to actully support full json5?
or is there some chance there was a new bug or regression since you posted this?Notepad++ v8.7.7 (64-bit)
Build time : Feb 6 2025 - 03:19:13
Path : C:\Program Files\Notepad++\notepad++.exe
Command Line : “C:\Program Files\Notepad++\readme.txt”
Admin mode : OFF
Local Conf mode : OFF
Cloud Config : OFF
Periodic Backup : ON
Placeholders : OFF
DirectWrite : OFF
Multi-instance Mode : monoInst
File Status Auto-Detection : cdEnabledNew (for current file/tab only)
Dark Mode : OFF
OS Name : Windows 11 Pro (64-bit)
OS Version : 23H2
OS Build : 22631.4890
Current ANSI codepage : 1252
Plugins :
JsonTools (8.3.1)
mimeTools (3.1)
NppConverter (4.6)
NppExport (0.4) -
@sdurham said in JSON5 formatted data cannot be fully collapsed.:
It seems to recognize the file as json5 but lists many errors, pretty much the same as posted earlier in this thread.
By “it”, do you mean the JsonTools plugin’s panel lists those as errors? Or do you mean Notepad++ syntax highlighting still lists those as errors.
Because until the underlying library that Notepad++ uses for syntax highlighting supports the JSON5 edge cases, Notepad++ natively cannot; installing the JsonTools plugin doesn’t affect the syntax highlighting, and will not fix that.
On the other hand, the JsonTools plugin can recognize the structure of the JSON5, so its TreeView panel should correctly show/navigate those nodes, despite Notepad++ syntax highlighting.
And if you don’t like all the errors being as obvious as in the prior screenshots, you can use Settings > Style Configurator > Language:
JSON
> Style:ERROR
and change the color so that it’s not black-on-orange (or yellow-on-red in my screenshot) – if you pick a color close to the normal PROPERTY NAME color, it probably wouldn’t be very obtrusive to you – like
vs
For the example, I picked a color that was different, but not annoyingly so; you could obviously pick any color you wanted – even the exact same color as PROPERTY NAME, if you wanted.
-
@sdurham
Have you tried changing thelogger_level
setting toJSON5
? As described in the documentation, the parser will log errors for many JSON5 features unless you do that.If you can give me an example of valid JSON5 (can be parsed by some major parser) that JsonTools v8.3.1 logs an error on when logger_level is JSON5, that is a bug and I will fix it.