Donny V.
Donny V.

Reputation: 23546

How to reformat JSON in Notepad++

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.

Upvotes: 1414

Views: 1741288

Answers (19)

Arvind Chourasiya
Arvind Chourasiya

Reputation: 17422

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

Upvotes: 46

DevMJ
DevMJ

Reputation: 3061

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

Upvotes: 251

Hardik Leuwa
Hardik Leuwa

Reputation: 3802

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

Upvotes: 318

Dan
Dan

Reputation: 18714

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.

Upvotes: 1809

SharpC
SharpC

Reputation: 7454

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.

Upvotes: 5

Azzabi Haythem
Azzabi Haythem

Reputation: 2413

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

Upvotes: 9

Nitin Lawande
Nitin Lawande

Reputation: 613

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.

Upvotes: 12

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.

Upvotes: 4

jslmsca
jslmsca

Reputation: 334

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.

Upvotes: 2

olliaroa
olliaroa

Reputation: 81

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.

Upvotes: 5

ibr
ibr

Reputation: 439

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++

Upvotes: 10

Esko Piirainen
Esko Piirainen

Reputation: 1379

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.

Upvotes: 4

JRL
JRL

Reputation: 77993

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()";
            }
            ];
        }
    }
}

Upvotes: 44

Josh
Josh

Reputation: 557

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)

Upvotes: 3

Stonetip
Stonetip

Reputation: 1178

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

Upvotes: 3

DevBezz
DevBezz

Reputation: 103

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

Upvotes: 3

SUN
SUN

Reputation: 79

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

Upvotes: 7

Millhouse
Millhouse

Reputation: 742

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.

Upvotes: 7

Richard Lloyd
Richard Lloyd

Reputation: 45

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.

Upvotes: 3

Related Questions