1085

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.

Ola Ström
  • 917
  • 1
  • 8
  • 23
Donny V.
  • 19,411
  • 13
  • 59
  • 76

23 Answers23

1467

Update:

As of Notepad++ v7.6, use Plugin Admin to install JSTool per this answer

INSTALL

Download it from http://sourceforge.net/projects/jsminnpp/ and copy JSMinNpp.dll to plugin directory of Notepad++. Or you can just install "JSTool" from Plugin Manager in Notepad++.

New Notepad++ install and where did PluginManager go? See How to view Plugin Manager in Notepad++

{
  "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.

scw
  • 4,862
  • 7
  • 29
  • 45
Dan H
  • 15,286
  • 1
  • 24
  • 21
  • 122
    Seems to be listed as JSTool now – Mike Henry Sep 14 '13 at 23:21
  • 6
    Thanks. I checked. I ended up using JSONViewer as it is lets format the JSON data and not just view it in nested tree format. – smile.al.d.way May 13 '14 at 17:55
  • 12
    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. – prograde Nov 27 '14 at 10:50
  • did anybody noticed the color after beautify ? – Prakash Apr 21 '15 at 19:29
  • Ascii plugin: http://sourceforge.net/projects/jsminnpp/files/Asc/JSToolNPP.1.16.10.asc.zip/download – redDevil Jul 06 '15 at 05:56
  • 14
    This can be installed directly from the built in "Plugin Manager" in Notepad++. Go "Plugins > Plugin Manager > Show Plugin Manager > Available tab" – Dib Feb 24 '16 at 15:30
  • Default settings seem to configure the hot key **Ctrl** + **Alt** + **M** for JSFor**m**at and **Ctrl** + **Alt** + **J** for **J**son Viewer – Chris Marisic Nov 24 '16 at 00:34
  • @prograde I did added the same way,the answer did help as I was earlier searching for just json under languages + plugins. – Amanpreet Jan 25 '17 at 12:14
  • 4
    A 64-bit version can be downloaded directly from here: https://notepad-plus-plus.org/community/topic/13064/plugin-update-jsonviewer-1-24 – brentlightsey Aug 14 '17 at 21:20
  • 1
    `CTRL + ALT + M` FTW – cmeza Feb 27 '18 at 19:26
  • Opening the plugin manager I found JSON Viewer right on the list. Worked great on a 10mb string – Kyle Postlewait Mar 26 '18 at 09:06
  • If you need to get the Plugin Manager first go: https://github.com/bruderstein/nppPluginManager/releases – Bruno Bieri Jun 04 '18 at 09:44
  • 1
    This still works even in Notepad++ v7.5.8. I just paste the downloaded `JSMinNPP.dll` file in the plugins folder of Notepad++. No need to create a folder to contain `JSMinNPP.dll`. – user3437460 Nov 13 '18 at 09:39
  • 1
    Notepad++ 7.6 was released a couple weeks ago and introduced the built-in Plugins Admin, making it super easy to install JSTool: https://notepad-plus-plus.org/news/notepad-7.6-released.html – Pilot_51 Nov 26 '18 at 17:20
  • 2
    This plugin is no longer compatible with v.7.5.9 and is automatically disabled. – Martin of Hessle Dec 13 '18 at 14:26
  • 1
    The plugin still works for me as of Notepad v7.6.1. Try putting the DLL in its own plugin directory (i.e. `plugins/JSMinNPP/JSMinNPP.dll`) – Dan H Dec 14 '18 at 21:08
  • It will also minify, which is a nice feature. – Justin Braaten Jan 24 '19 at 18:59
  • @Prakash I guess you mean when you use it on a JSON that has an extension it doesn'trecognize as JSON, such as .txt or .mcmeta? Yeah, apparently it properly recognizes such files as JSON after you do anything JSTool with them. A neat and useful side effect. – Egor Hans Nov 01 '20 at 15:22
  • 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. – JG1212 Feb 11 '21 at 16:29
146

For Notepad++ v.7.6 and above Plugins Admin... is available.

  1. Open Menu Plugins > Plugins Admin...

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

We can install any Notepad++ supported plugins using Plugins Admin...

Hardik Leuwa
  • 1,946
  • 2
  • 10
  • 25
  • 4
    This is a very simple technique. Thanks. I just want to add in order to format after installing the plugin one needs 1) **Select** JSON objects 2) Go to **plugins ** 3)**JSON Viewer** accordion 4) Lastly, **Format JSON**. **OR** Just hit **Cntrl + Shift + Alt + M** – Yashwin Munsadwala May 15 '19 at 16:51
  • 4
    plugins > Plugins admin no longer works in the current version. – Michael Tuchman Nov 01 '19 at 20:07
  • 1
    @Michael Tuchman, May i know in which version Plugins > Plugins Admin... not work? – Hardik Leuwa Nov 02 '19 at 05:47
  • 1
    I have test Plugins > Plugins Admin... by JSON Viewer in latest version Notepad++ v7.8 and its working properly – Hardik Leuwa Nov 02 '19 at 05:57
  • @Hardik Leuwa : 7.6.6 (64 bit) – Michael Tuchman Nov 07 '19 at 05:33
  • 1
    @Michael Tuchman, I have tested Plugins Admin.. in Notepad ++ 7.6.6 (64 bit) by this same JSON sample asked in question. and its working properly. – Hardik Leuwa Nov 07 '19 at 05:51
  • 1
    It works for my Notepad++ 7.8. Just make sure that your proxy is in place so the download background job can finish it job (no warnings or whatsoever if fails. Let it restart by itself. – TGU Sep 17 '20 at 18:40
86

You require a plugin to format JSON. To install the plugin do the following steps:

  1. Open notepad++ -> ALT+P -> Plugin Manager -> Selcet JSON Viewer -> Click Install
  2. Restart notepad++
  3. Now you can use shortcut to format json as CTRL + ALT +SHIFT + M or ALT+P -> Plugin Manager -> JSON Viewer -> Format JSON

enter image description here

DevMJ
  • 1,211
  • 8
  • 13
58

I personally use JSON Viewer since the Notepad++ plugin doesn't work any more.

EDIT - 24th May 2012

I advise that you download the JSMin plugin for Notepad as mentioned in the answer. This works well for me in the latest version (v6.1.2 at time of writing).

EDIT - 7th November 2017

As per @danday74's comment below, JSMin is now JSToolNpp. Also, please be aware that the JSON Viewer tool is on Codeplex which will likely disappear in the near future.

Given the above, this answer is no longer relevant and you should use Dan H's answer instead. My answer is simply here for posterity.

Community
  • 1
  • 1
Dan Atkinson
  • 10,801
  • 12
  • 78
  • 106
40

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()";
            }
            ];
        }
    }
}
Pang
  • 8,605
  • 144
  • 77
  • 113
JRL
  • 72,358
  • 17
  • 90
  • 140
6

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

ibr
  • 269
  • 4
  • 15
5

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.

Millhouse
  • 722
  • 1
  • 8
  • 17
  • 1
    @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. – galaktor Oct 19 '12 at 08:21
  • 2
    Online json formatters are good but sometimes you don't want to risk sending the data you're formatting across the Internet. – C.M. Nov 11 '19 at 19:20
4

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

SUN
  • 49
  • 1
  • 1
4

If formatting JSON is the main goal and you have VisualStudio then it is simple and easy.

  1. Open Visual Studio
  2. File -> New -> File
  3. Select Web in left side panel
  4. Select JSON
  5. Copy paste your raw JSON value
  6. Press Ctrl + K and Ctrl + D

That's it. you will get formatted JSON Value.

User0106
  • 489
  • 1
  • 4
  • 13
  • 6
    The question is about Notepad++ – Toto Jun 21 '19 at 11:25
  • I was searching tool for format JSON values and found this link. Later I found Visual studio steps. It may useful for someone who is looking for formatting JSON values. – User0106 Jun 24 '19 at 10:03
  • I usually resort to using this since my developer environment is reset from contract to contact. I just paste it into any .json, select all, copy, then undo. – C.M. Nov 11 '19 at 19:33
4

As per the latest notepad++, updated answer. Install JSON Viewer

Open notepad++ go to Plugins --> click Plugins Admin..

enter image description here

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

enter image description here

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

enter image description here

R15
  • 9,066
  • 8
  • 50
  • 105
3

The following Notepad++ plugin worked for me as suggested by "SUN" https://sourceforge.net/projects/jsminnpp/

Siva
  • 503
  • 4
  • 6
2

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.

olliaroa
  • 51
  • 7
1

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)

Josh
  • 537
  • 1
  • 7
  • 21
1

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.

1

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.

Esko Piirainen
  • 1,028
  • 1
  • 11
  • 25
1

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

DevBezz
  • 43
  • 5
1

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

Stonetip
  • 1,092
  • 10
  • 20
0

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.

jslmsca
  • 115
  • 1
  • 12
0

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.

Henke
  • 1,466
  • 2
  • 9
  • 22
0

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.
Nitin Lawande
  • 380
  • 1
  • 2
  • 8
-1

You can use http://www.jsonlint.com/ to edit your json online if you don't have Notepad++.

Ahmed Magdy
  • 5,256
  • 8
  • 36
  • 74
-8

I know you asked about NotePad++ but TextMate for OS X can do it via the JSON bundle, its called the "Reformat Document" command.

Cody Caughlan
  • 31,132
  • 4
  • 58
  • 66
-10

Your best bet is to use one of the latest versions of Eclipse (I am using Eclipse Galileo J2EE and Eclipse Ganymede J2EE). Create a JavaScript file, then create a variable:

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

Lastly, hit CTRL+SHIFT+F and voila! You have a nicely indented JSON Object. I, too, am looking for a Notepad++ JSON formatter, and I very well may be forced to develop an Npp plugin some short time in the future.

shA.t
  • 15,232
  • 5
  • 47
  • 95
  • 1
    If you have Visual Studio, simply paste the json text into a new file and it will be formatted automatically. – Sergey OCHKIN Jun 06 '16 at 06:31
  • *I, too, am looking for a Notepad++ JSON formatter,* If you have same question please don't add an answer like this and keep SO clean ;). – shA.t Sep 10 '17 at 15:37