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.
Solution 1:
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()"
}
]
}
}
}
Tip: Select the code you want to reformat, then Plugins | JSTool | JSFormat.
Solution 2:
For Notepad++ v.7.6 and above Plugins Admin... is available.
Open Menu Plugins > Plugins Admin...
Search JSON Viewer
Check JSON Viewer in List
Click on Install Button
Restart Notepad++
Select JSON text
Go to Plugins > JSON Viewer > Format JSON ( Ctrl + Alt + Shift + M )
We can install any Notepad++ supported plugins using Plugins Admin...
Solution 3:
You require a plugin to format JSON. To install the plugin do the following steps:
- Open notepad++ -> ALT+P -> Plugin Manager -> Selcet JSON Viewer -> Click Install
- Restart notepad++
- Now you can use shortcut to format json as CTRL + ALT +SHIFT + M or ALT+P -> Plugin Manager -> JSON Viewer -> Format JSON