tags:

views:

3195

answers:

9

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.

A: 

No, not at this time.

:)

Andrew Myhre
A: 

I usually copy&paste code to Eclipse and there press CTRL+SHIFT+F (format code). But I did not try it yet on JSON.

Trick
Just tried in Eclipse, don't work for JSON.
Trick
A: 

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
+19  A: 

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()";
            }
            ];
        }
    }
}
JRL
You rock! Thanks
Donny V.
unfortunately, this does not work with the newest Unicode version of Notepad++ 5.5
Anthony Shaw
Use the new Plugin Manager to download the version you need.
Donny V.
Just tried to install this plugin using Plugin Manager and it failed.
Bob
+1  A: 

A JSON pretty printer in javascript

Bill Casarin
It seems to give up at the end, forgetting to indent the rest of the braces.
Dan Atkinson
+2  A: 

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

Dan Atkinson
+1  A: 

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.

Richard
nice. thanks for the tip.
neesh
A: 

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.

Brett McLaughlin
+1  A: 

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