JSON Formatter Plugin for IntelliJ

When developing an AJAX application you often end up with some data interchange format, like XML, plain text, or, in my case: JSON. The trouble with JSON, however, it that's it's quite hard to read. Not because it's so complicated, but because it has been optimized for network communication, which in this case, means: all the whitespace has been stripped. Wouldn't it be nice to have an integrated JSON formatter in your IDE to handle this? Well, now it possible!


What I did was to create a plugin for IntelliJ, to format your JSON code into some more readable (and formatted) code. Since a picture says more than a thousand words: a picture for your viewing pleasure:

IntelliJ JSON Formatter

What you can see in the screenshot is the following JSON code, but formatted:

{"glossary":{"GlossDiv":{"GlossList":{"GlossEntry":{"Abbrev":"ISO 8879:1986","Acronym":"SGML","GlossDef":{"GlossSeeAlso":["GML","XML"],"para":"A meta-markup language, used to create markup languages such as DocBook."},"GlossSee":"markup","GlossTerm":"Standard Generalized Markup Language","ID":"SGML","SortAs":"SGML"}},"title":"S"},"title":"example glossary"}}

By pasting the above in the plugin, and clicking on 'format', you'll end up with the result as seen in the screenshot, which is much more readable, and thanks to the RSyntaxTextArea has colors and braces matching. The plugin doesn't do validation yet, but this is a helpful addition to make the JSON even more readable!

So, please check out the plugin (you can install it from IntelliJ's integrated plugin manager), install the JSON Formatter plugin and tell me what you think of it!

Comments (4)

  1. Vivek - Reply

    February 9, 2009 at 10:56 pm

    Hey,

    I tried your plugin, its really good. I can suggest two features. one is converting the formatted json to xml and the other is converting it into tree structure. If you can share the code may be I can help with the development. Let me know . my email is

    vivekmongolu at gmail dot com

    Thanks,
    Vivek

    wanted to extend it further by

  2. Dmitry - Reply

    October 26, 2012 at 1:50 am

    Indeed, very handy.

    Would be great to have it:
    1. Integrated into Idea formatting framework so you can customize presentation
    2. Display as tree +1

  3. Johny - Reply

    December 11, 2012 at 4:45 pm

    Can you please add a checkbox to disable validation.

  4. Greg - Reply

    February 20, 2013 at 10:25 pm

    One suggestion/request or question. Can this be integrated with the comparison tool in IntelliJ. Would be great for unit tests to see differences (readily) between expected and actual JSON strings.

Add a Comment