Community
    • Login

    JsonTools v5.5. is live!

    Scheduled Pinned Locked Moved Notepad++ & Plugin Development
    jsonjsonviewerplugins
    22 Posts 4 Posters 10.2k 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.
    • MarkusBodenseeM
      MarkusBodensee @Mark Olson
      last edited by

      @Mark-Olson said in JsonTools v5.5. is live!:

      JsonTools v7.1.0 is live! Hopefully it will be in the version of the Plugin List that ships with Notepad++ 8.5.5. You should definitely upgrade to this version, especially if you have Notepad++ 8.6.3 or newer.

      I think you mean the Plugin List that ships with Notepad++ 8.6.5

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

        JsonTools v8.0 is now live, and the most notable change is that it can now be translated to other languages.

        76bf24bd-92a2-486b-a8b0-b325cc4add70-image.png

        I would be particularly interested in getting feedback from other C# plugin developers, particularly @Bas-de-Reuver, on the API I devised for translating forms using JSON with comments files and a somewhat hacky algorithm for translating WinForm controls while avoiding collisions. I am currently planning to add this code (or possibly a variant that uses XML instead of JSON with comments) to my NppCSharpPluginPack plugin template.

        1 Reply Last reply Reply Quote 2
        • conky77C conky77 referenced this topic on
        • Mark OlsonM
          Mark Olson
          last edited by Mark Olson

          JsonTools v8.2 is now downloadable via the Plugins Admin for Notepad++ 8.7.2. This version includes a variety of enhancements and bugfixes, but the main reason I wanted to post this here is that it attempts to fix a problem introduced in JsonTools v8.1, wherein decimal numbers had unnecessarily long representations (for example, 11.11 was reformatted as 11.109999999999999), and I’ve gotten a report that this issue is still not fixed in JsonTools v8.2, even though it is fixed on both of the two machines that I tested it on.

          So here’s my request: please upvote this comment if and only if you notice that JsonTools v8.2 reformats 11.11 as 11.109999999999999. Don’t upvote this comment for any other reason; that way, I’ll know that this is still an issue if I get upvotes.

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

            I’ve just commited the unreleased JsonTools v8.2.0.3 that hopefully fixes the issue described in my previous comment. Did my commit fix it? I have no idea, 🤷!

            Same deal as in my previous comment: please upvote this comment if and only if you notice that JsonTools v8.2.0.3 reformats 11.11 as 11.109999999999999. Don’t upvote this comment for any other reason; that way, I’ll know that this is still an issue if I get upvotes.

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

              JsonTools v8.4, which adds translation to several more languages and a few minor bugfixes, is live.

              It has been tested and appears to work well for versions of Notepad++ ranging from 7.3.3 to 8.8.1, both 32-bit and 64-bit.

              1 Reply Last reply Reply Quote 3
              • User NameU
                User Name
                last edited by

                How to enable auto JSON format in JsonToolsNppPlugin?

                Mark OlsonM 1 Reply Last reply Reply Quote 0
                • Mark OlsonM
                  Mark Olson @User Name
                  last edited by

                  @User-Name

                  You’ll have to clarify what you mean by “auto JSON format”. If you mean “automatically format JSON when you open a file”, I’m sorry but I have chosen not to implement this feature.

                  If you’re curious, I haven’t implemented automatic reformatting for the following reasons:

                  • keyboard shortcuts and icons exist for both pretty-printing and compressing JSON, and it only takes a fraction of a second to execute the keyboard shortcut
                  • reformatting JSON can take a long time on large JSON files, so automatically reformatting them would delay them from actually getting to work on the file.
                  • The whole point of having a tree viewer is to allow for easy navigation of the document without reformatting it
                  • By default, reformatting JSON removes comments
                  • If something is rendered in JSON5, it will be converted into the corresponding JSON representation when reformatting, and there is no way to turn this behavior off. For example, {foo: 'bar', baz: 0xf} will be reformatted to {"foo": "bar", "baz": 15}.
                  • JsonTools already has too many user-configurable settings that few people ever use. Why add another?
                  User NameU 1 Reply Last reply Reply Quote 2
                  • Mark OlsonM
                    Mark Olson
                    last edited by

                    JsonTools v8.4.0.4 is live, with support for arbitrarily large integers.

                    This is not a strict upgrade to JsonTools v8.4, the latest version on the plugins manager, because using BigInteger to store integers comes with a hefty performance cost relative to the 64-bit long that I had been using previously. You should only use this version if you need it.

                    As such, JsonTools is being bifurcated for the foreseeable future, with every future release available on the plugin manager using 64-bit integers, and the BigInteger branch only being updated as needed to remedy serious bugs.

                    1 Reply Last reply Reply Quote 0
                    • User NameU
                      User Name @Mark Olson
                      last edited by

                      @Mark-Olson said in JsonTools v5.5. is live!:

                      @User-Name

                      You’ll have to clarify what you mean by “auto JSON format”. If you mean “automatically format JSON when you open a file”, I’m sorry but I have chosen not to implement this feature.

                      If you’re curious, I haven’t implemented automatic reformatting for the following reasons:

                      • keyboard shortcuts and icons exist for both pretty-printing and compressing JSON, and it only takes a fraction of a second to execute the keyboard shortcut
                      • reformatting JSON can take a long time on large JSON files, so automatically reformatting them would delay them from actually getting to work on the file.
                      • The whole point of having a tree viewer is to allow for easy navigation of the document without reformatting it
                      • By default, reformatting JSON removes comments
                      • If something is rendered in JSON5, it will be converted into the corresponding JSON representation when reformatting, and there is no way to turn this behavior off. For example, {foo: 'bar', baz: 0xf} will be reformatted to {"foo": "bar", "baz": 15}.
                      • JsonTools already has too many user-configurable settings that few people ever use. Why add another?

                      Yes, you’re absolutely right—I did mean automatically formatting the document into a readable form when opening a file. Nobody will force you to use this feature, but perhaps someone else might want to. You don’t need to make decisions for all users.

                      (Sorry for my poor English.)

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

                        @User-Name
                        I’ve decided that, while I still don’t want to implement this feature in JsonTools, I would create a PythonScript script that allows you to run any JsonTools command as soon as a file is opened. The script (shown below) is self-documenting.

                        '''
                        ====== SOURCE ======
                        Requires PythonScript (https://community.notepad-plus-plus.org/topic/23039/faq-how-to-install-and-run-a-script-in-pythonscript)
                        Also requires JsonTools (https://github.com/molsonkiko/JsonToolsNppPlugin)
                        Based on this question: https://community.notepad-plus-plus.org/post/102686
                        ====== DESCRIPTION ======
                        When opening a file with the "json" file extension (this is customizable),
                        pretty-print or compress (user's choice) the entire document.
                        
                        This behavior is disabled for files larger than 4 megabytes (this is also customizable).
                        
                        Every time this script is run, the behavior is reset to match the user's current preferences.
                        So you can just edit the configuration values (ALL_CAPS variable names below), resave the file, and re-run this script to tweak its behavior.
                        ====== EXAMPLE ======
                        1. If this script is run with the default settings, as soon as a file is opened with the text
                                {"foo":["bar","baz",true],"qutn":[-1.5,1000,null]}
                            and the name "blah.json", it will be reformatted to
                                {
                                    "foo": ["bar", "baz", true],
                                    "qutn": [-1.5, 1000, null]
                                }
                            (the result depends on JsonTools settings)
                        2. However if a file with the same text and the name "blah.json5" is opened,
                            it will NOT be reformatted because "json5" is not in FILE_EXTENSIONS_TO_REFORMAT.
                        3. If a file with name "blah2.json" and length 40000000 (40 megabytes) is opened,
                            it will NOT be reformatted either, because its length is greater than MAX_LENGTH_TO_REFORMAT.
                        ====== RUNNING THIS SCRIPT AT STARTUP ======
                        Creating this script is not sufficient to make it run when Notepad++ starts up.
                        
                        To do that, you must:
                        1. open the "startup.py" script (in the same directory as this script) and add the following line (with no leading indentation) at the END:
                            import jsontools_pretty_print_on_file_open
                        2. Go to "Configuration..." on the PythonScript plugin menu and choose ATSTARTUP for the "Initialisation" option.
                        3. Close and restart Notepad++ to confirm that this script ran at startup.
                        '''
                        from __future__ import print_function
                        from Npp import notepad, editor, NOTIFICATION
                        
                        PRETTY_PRINT_COMMAND_NAME = 'Pretty-print current JSON file'
                        COMPRESS_COMMAND_NAME = 'Compress current JSON file'
                        OPEN_TREE_COMMAND_NAME = 'Open JSON tree viewer'
                        
                        COMMAND_NAME_USED = PRETTY_PRINT_COMMAND_NAME
                        
                        PLUGIN_NAME = 'JsonTools'
                        
                        MAX_LENGTH_TO_REFORMAT = 4e6
                        
                        FILE_EXTENSIONS_TO_REFORMAT = ['json'] # could also add 'json5' or maybe 'jsonc'
                        
                        def run_jsontools_command_on_file_open(args):
                            fname = notepad.getCurrentFilename()
                            length = editor.getLength()
                            fname_ok = any(fname.endswith('.' + ext) for ext in FILE_EXTENSIONS_TO_REFORMAT)
                            if length <= MAX_LENGTH_TO_REFORMAT and fname_ok:
                                notepad.runPluginCommand(PLUGIN_NAME, COMMAND_NAME_USED)
                                print('ran command "%s" on file "%s" with length %d' % (COMMAND_NAME_USED, fname, length))
                        
                        
                        # this runs when this script is run, and sets run_jsontools_command_on_file_open to run when a file is opened
                        notepad.clearCallbacks(run_jsontools_command_on_file_open, [NOTIFICATION.BUFFERACTIVATED])
                        notepad.callback(run_jsontools_command_on_file_open, [NOTIFICATION.BUFFERACTIVATED])
                        print('From now on, the %s command "%s" will run when files with length <= %d with an extension in %s are opened' % (
                            PLUGIN_NAME,
                            COMMAND_NAME_USED,
                            MAX_LENGTH_TO_REFORMAT,
                            FILE_EXTENSIONS_TO_REFORMAT,
                        ))
                        
                        User NameU 1 Reply Last reply Reply Quote 1
                        • User NameU
                          User Name @Mark Olson
                          last edited by

                          @Mark-Olson , thanks! But it works from the second file. In the Python console I see

                          From now on, the JsonTools command "Pretty-print current JSON file" will run when files with length <= 4000000 with an extension in ['json'] are opened
                          Python 2.7.18 (v2.7.18:8d21aa21f2, Apr 20 2020, 13:25:05) [MSC v.1500 64 bit (AMD64)]
                          Initialisation took 31ms
                          Ready.
                          

                          And then if I open any file, it opens formatted. But the first opened file is not formatted :)"

                          Mark OlsonM 1 Reply Last reply Reply Quote 0
                          • Mark OlsonM
                            Mark Olson @User Name
                            last edited by

                            @User-Name said in JsonTools v5.5. is live!:

                            And then if I open any file, it opens formatted.

                            Glad to hear it!

                            But the first opened file is not formatted :)

                            That’s probably just a limitation of how PythonScript is implemented, and I don’t think there’s anything I can do about that.

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