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.