Community
    • Login

    double click on a JSON file >> Notepad++ should (auto-) run the well JSON formating

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    2 Posts 2 Posters 5.3k 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.
    • MatthiasBTHM
      MatthiasBTH
      last edited by

      Hi,

      I have to handle a lot of JSON files. They are always “compressed”, without blanks and tabs. So far ok! With a double click (yes windows world), Notepad will be opened, file loaded (because I my setting file extension 2 linked application is to Notepad++) So far ok!

      There are different JSON plugins available. With a shortcut (or via the menu) I can run a well formated JSON (with tabs, LF/CR, etc). So far ok!

      I am looking for a option, that all new opened JSON files will directly (auto-) run the well formating of the JSON file.

      Is this possible?
      Thanks a lot in advance!

      Matthias.

      dinkumoilD 1 Reply Last reply Reply Quote 0
      • dinkumoilD
        dinkumoil @MatthiasBTH
        last edited by dinkumoil

        @MatthiasBTH

        To solve your issue you need support by some kind of scripting plugin, for example NppExec plugin and its companion NppEventExec.

        1. Install NppExec and NppEventExec plugins using Plugins Admin.
        2. After Notepad++ has been restarted navigate to (menu) Plugins -> NppExec -> Execute NppExec Script
        3. In the dialog popping up enter the following script:
        npp_console keep
        npp_menucommand Path/To your JSON formatting plugin's/menu entry 
        

        If your are using for example JSTool plugin to format your JSON files, line 2 of the script above has to be npp_menucommand Plugins/JSTool/JSFormat. In case you are using JsonTools plugin, line 2 of the script above has to be npp_menucommand Plugins/JsonTools/Pretty-print current JSON file. Please note: The menu entry’s path is case sensitive and has to be localized. That means, if the Plugins menu has another name in your Notepad++ UI language, you need to adapt the command accordingly.

        1. Click button Save.
        2. In the small dialog popping up enter AutoFormatJson as name for the script.
        3. Click button Save to close the saving dialog.
        4. Click button Cancel to close the script editing dialog.
        5. Navigate to (menu) Plugins -> NppEventExec -> Edit rules
        6. In the toolbar at the left, click button Add a new rule (mouse-hover over the buttons to get their tooltip texts).
        7. In the toolbar at the left, click button Edit the selected rule.
        8. Create a new rule by entering the following data into the dialog popping up (Please note: The edit field NppExec command has to contain the name of the NppExec script you saved in step 5. Edit field Regex has to contain the following: (?i).*\.json):

        a0ef2c92-f43c-4f8c-8777-243f69d2e55d-grafik.png

        1. Click button Apply to close the rule editing dialog.
        2. In plugin’s main dialog click button Save to save your changes.
        3. Click button Close to close plugin’s main dialog.

        Now you can load a JSON file and it should be pretty-printed automatically.

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