Blog

JSON Formatter Plugin for IntelliJ

05 Feb, 2009
Xebia Background Header Wave

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!

Questions?

Get in touch with us to learn more about the subject and related solutions

Explore related posts