1439

I need Notepad++ to take a JSON string from this

{"menu": {"id": "file","value": "File","popup": {"menuitem": [{"value": "New", "onclick": "CreateNewDoc()"},{"value": "Open", "onclick": "OpenDoc()"},{"value": "Close", "onclick": "CloseDoc()"}]}}}

to this...

{"menu": {
  "id": "file",
  "value": "File",
  "popup": {
    "menuitem": [
      {"value": "New", "onclick": "CreateNewDoc()"},
      {"value": "Open", "onclick": "OpenDoc()"},
      {"value": "Close", "onclick": "CloseDoc()"}
    ]
  }
}}

I looked around at all the TextFX options but couldn't find anything that worked.

0

19 Answers 19

1851

Use JSTool

As of Notepad++ v7.6, you can use the Plugin Admin option in Notepad++ to install JSTool.

Manual Install

  1. Download it from https://www.sunjw.us/jstool/npp/#download
  2. Copy JSMinNpp.dll to the plugin directory of Notepad++. You may need to create a directory named "JSMinNPP" in the plugin directory after version 7.6.3

Here's an example of JSON that's been formatted using the tool:

{
  "menu" : {
    "id" : "file",
    "value" : "File",
    "popup" : {
      "menuitem" : [{
      "value" : "New",
          "onclick" : "CreateNewDoc()"
        }, {
          "value" : "Open",
          "onclick" : "OpenDoc()"
        }, {
          "value" : "Close",
          "onclick" : "CloseDoc()"
        }
      ]
    }
  }
}

enter image description here

Tip: Select the code you want to reformat, then Plugins | JSTool | JSFormat.

Sign up to request clarification or add additional context in comments.

6 Comments

JSTool can also format the JSON data. Just press Ctrl-Alt-M. I tried a few plugins now and I find this is the best one.
This can be installed directly from the built in "Plugin Manager" in Notepad++. Go "Plugins > Plugin Manager > Show Plugin Manager > Available tab"
If JSTOOL and JSONVIEWER are not working, make sure the file is NOT opened from inside a .zip file. For some reason most plugins don't work correctly when the file is opened in windows from within a zip file. Just extract the file first, then open in NP++ and plugins will work fin.
Formatting isn't compatible with folding, unfortunately. Quite annoying.
@Derek White: i have notepad++ v8.7.5 and i can do folding with JStool.
|
328

You can use JSON Viewer. For Notepad++ v.7.6+, Plugins Admin... is available to install it:

  1. Open the Menu option "Plugins" -> "Plugins Admin..."
  2. Search for "JSON Viewer"
  3. Check JSON Viewer in List
  4. Click on Install Button
  5. Restart Notepad++
  6. Select JSON text
  7. Go to "Plugins" > "JSON Viewer" > "Format JSON ( Ctrl + Alt + Shift + M )"

3 Comments

FYI, I did not have a menu option for Plugins Admin in v7.9.1 32-bit- at least as a non-admin user. I do have it on 7.9.5 64-bit and up, for both admins and not. (Installing plugins does however require admin rights, sadly.)
JSON Viewer cannot parse log structured output from Serilog, for example. JSTool worked without problems.
awesome ... ...
252

Notepad++ requires a plugin to format JSON. You can use the JSON Viewer plugin to do this. To install the plugin, do the following steps:

  1. Open Notepad++ -> press Alt + P -> select Plugins Admin (or Plugin Manager in older versions of Notepad++) -> select JSON Viewer -> click Install
  2. Restart Notepad++
  3. Now you can use this shortcut to format JSON: Ctrl + Alt + Shift + M, or press Alt + P -> select Plugin Manager -> select JSON Viewer -> select Format JSON

enter image description here

2 Comments

This format algorithm is not robust and fails often, the JSTool (see answer of ibr) is much more robust.
@Stefan I can confirm. JSTool was able to parse log structured output from Serilog (.NET Core 6).
48

Add the JSON Viewer Plugin

Open Notepad++, go to Plugins, click "Plugins Admin..."

enter image description here

In the Plugins Admin window, search for JSON Viewer and click on Install

enter image description here

Now after installing the plugin, this is how you can view file in JSON format

enter image description here

Comments

44

Universal Indent GUI plugin for Notepad++ will turn your sample into:

{
    "menu" : {
        "id" : "file", "value" : "File", "popup" : {
            "menuitem" : [ {
                "value" : "New", "onclick" : "CreateNewDoc()";
            }
            , {
                "value" : "Open", "onclick" : "OpenDoc()";
            }
            , {
                "value" : "Close", "onclick" : "CloseDoc()";
            }
            ];
        }
    }
}

1 Comment

unfortunately, this does not work with the newest Unicode version of Notepad++ 5.5
12

Steps to add JSON viewer plugin for notepad++:

  1. Download JSON viewer plugin for notepad++ from sourceforge.
  2. Copy NPPJSONViewer.dll into Notepad++\plugins\NPPJSONViewer folder
  3. restart the notepad++
  4. select JSON and click on plugins > JSON Viewer > Format JSON (CTRL+ALT+SHIFT+M).
  5. Done.

2 Comments

Notepad++ says that plugin is not compatible with 64bit version of notepad , do we have any 64bit plugin ?
10

simply go to this link download the dll copy and paste the dll to the plugins folder at notepad++, \Notepad++\plugins restart the notepad++, and it should be shown in the list

jsformatter

NOTE: this dll supports 64 bit notepade++

Comments

9

you can use Notepad++ to format Json using Plugin Admin and JSTool but for those who can't install this plugin they can use Postman to Beautify json like this:

enter image description here

Comments

7

It's not an NPP solution, but in a pinch, you can use this online JSON Formatter and then just paste the formatted text into NPP and then select Javascript as the language.

2 Comments

@Brent.Longborough Thanks for that little nugget of advice! The JS highlighting has a weird gray background, python highlighting is much easier on the eyes.
Online json formatters are good but sometimes you don't want to risk sending the data you're formatting across the Internet.
7

JSMinNpp plugin will do this job. https://sourceforge.net/projects/jsminnpp/

Comments

5

You can view in Notepad++ no problem now (maybe older versions were bugged?)

for win64: You can find the latest plugin here: https://github.com/kapilratnani/JSON-Viewer/releases . The latest zip file contains a .dll file.

And then follow the github priject README instructions:

  1. Paste the file "NPPJSONViewer.dll" to Notepad++ plugin folder
  2. open a document containing a JSON string
  3. Select JSON fragment and navigate to plugins/JSON Viewer/show JSON Viewer or press "Ctrl+Alt+Shift+J"
  4. Voila!! if the JSON is valid, it will be shown in a Treeview

It should be the same process for win32 but I cannot personally verify it.

Comments

5

I didn't have the Plugins Admin option, so the easiest way was to reinstall Notepad++ first (I was using v8.5.8) and select:

  • Plugins
  • Plugins Admin

(Also I simply reinstalled Notepad++ over the top of the previous install, I didn't uninstall first.)

In Notepad++ I then went to Plugins → Plugins Admin and searched for the plugins I wanted:

  • JSON Tools
  • XML Tools (press Next if when you search "XML" the first one that comes up is "Npp Xml Treeview" instead).

I ticked them both then clicked Install.

1 Comment

FYI, the pretty print function included in the JSON tools package, will delete content if it's not syntaxed properly. Ex: I had one JSON object on each line, without being wrapped in an array, and it formatted the first line's object, and deleted the other 2. Undo-ing and wrapping in the array, fixed it, but just something to keep in mind.
4

If you don't want to install a Notepad++ plugin but you have Firefox and a JSON plugin for Firefox, you can select Run -> Launch in Firefox. You get the contents formatted as JSON using your Firefox plugin.

This is what I personally do.

Comments

4

I use 32-bit Notepad++ version 7.5.6. I have found that 32-bit JSToolNpp 1.20.0 does a great job.
The direct link is:
https://sourceforge.net/projects/jsminnpp/files/Uni/JSToolNPP.1.2006.0.uni.32.zip/download
which is redirected from https://sourceforge.net/projects/jsminnpp/.
VirusTotal link:
https://www.virustotal.com/gui/file/008ee0ce889dfd9e96b975cebe6faafe28bc350352e951f3dec97e8e5bec5a07

JSON-Viewer works fine too, but cannot sort the JSON data.

Comments

3

It worked for me in the latest edition to Notepad using the UniversalIndentGui.

What I did was under the plugin setting choose Enable Text Auto Update, a window popped up and I selected javascript.

Comments

3

Notepad 5.8.7 and jsmin 1.7.0.0 works wonderful here.

Be careful though, found out jsmin eats the comments the hard way (should have read first).

Comments

3

I'm using the JSON Viewer plug-in with NPP 5.9 and it seems to work well.

Comments

3

I know this thread is old but I recently ran into a problem with JSToolNPP not being compatible with my newly updated N++, I did find a replacement that seems to work. http://sourceforge.net/projects/nppjsonviewer/

Use at your own risk, ofc. (standard disclaimer from me when linking anything outside the SExchange, fyi)

Comments

2

For those of us behind a corporate firewall with no direct access to the internet, using the Plugins Admin won't work. To use the JSMinNpp plugin, you can't just "copy the dll to the plugins folder". It needs to live inside a folder called "JSMinNpp" inside the plugins folder. After doing that and restarting Notepad++, I was able to see the "JSTool" menu option under the Plugins menu.

Tested with Notepad++ 7.8.2 and 7.8.9.

1 Comment

This appears to be a reply to an existing answer rather than an answer itself. Please only post new answers if you have novel solutions to the question. If you have pertinent information about an existing answer, leave a comment under the answer, instead.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.