Community
    • Login

    JSON5 formatted data cannot be fully collapsed.

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    7 Posts 4 Posters 414 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • fengyong jiaF
      fengyong jia
      last edited by

          {
            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,
          }
      

      2024-11-07_112105.png

      PeterJonesP 1 Reply Last reply Reply Quote 1
      • Mark OlsonM
        Mark Olson
        last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • PeterJonesP
          PeterJones @fengyong jia
          last edited by

          @fengyong-jia ,

          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):
          6edcc395-cfc9-4914-89b2-cf6d71b78ad7-image.png

          If I quote all the keys, instead of leaving them unquoted, the error indicators go away:
          112acc2f-9a70-4f0e-a7df-b963e2258757-image.png
          and I can fold the whole JSON5 from line 1 to line 22:
          efa10613-e590-4d85-9b30-a65dc07a0acf-image.png

          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.

          81612576-c93a-419a-b55d-8250f7ba236a-image.png 5c7dc54c-be8d-4dff-ac16-ba4e4a5aeacc-image.png

          So, in order for Notepad++ to have the ability to allow JSON5 keys to not be quoted,

          1. 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.
          2. Wait for Lexilla to implement it
          3. 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
          4. 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.

          1 Reply Last reply Reply Quote 3
          • Mark OlsonM
            Mark Olson
            last edited by

            FWIW the JsonTools plugin has full JSON5 support, so you can use its tree view to navigate JSON5 documents.

            S 1 Reply Last reply Reply Quote 3
            • S
              sdurham @Mark Olson
              last edited by

              @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)

              PeterJonesP Mark OlsonM 2 Replies Last reply Reply Quote 0
              • PeterJonesP
                PeterJones @sdurham
                last edited by

                @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
                b5512166-34db-4f1a-aecc-65ef03de493e-image.png
                vs
                913692a3-6cce-499b-b406-8b9651be34ac-image.png

                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.

                1 Reply Last reply Reply Quote 1
                • Mark OlsonM
                  Mark Olson @sdurham
                  last edited by

                  @sdurham
                  Have you tried changing the logger_level setting to JSON5? 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.

                  1 Reply Last reply Reply Quote 2
                  • First post
                    Last post
                  The Community of users of the Notepad++ text editor.
                  Powered by NodeBB | Contributors