IntelliJ JSON Formatter Plugin

Posted on February 5, 2009. Filed under: Grails, IntelliJ JSON Formatter Plugin | Tags: , , , , , |

I’ve just created my first IntelliJ plugin, a JSON formatter. Since I work a lot with Groovy and Grails, and Grails supports JSON so nicely, it’s sometimes necessary to debug the JSON code going back and from the client to the Grails backend. However, since the JSON code is stripped from whitespaces, it’s a bit harder to read than a nested structure. To format the JSON, you can use various websites , but it requires a context switch (from IDE to Webbrowser), plus it requires an Internet connection. To solve this, I created an IntelliJ JSON Formatter plugin, which nicely hooks into IntelliJ. To give you an idea of what the plugin looks like, please take a look at the following image:

IntelliJ JSON Formatter plugin

This images gives an impression of a formatted piece of JSON code, and also includes brace matching and coloring thanks to the RSyntaxTextArea. The JSON code is parsed with the help of the JSON tools from Berlios.

You can install the plugin by using IntelliJ’s integrated plugin manager. If you’ve used it, please give me some feedback! I’d like it!


Make a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

11 Responses to “IntelliJ JSON Formatter Plugin”

RSS Feed for Don’t mind the language Comments RSS Feed

Very nice. I have been looking for an offline formatter for awhile now. Seems that mac users can use textmate, but I don’t use a mac at work unfortunately.

Also, if you are interested, check out my latest blog on using groovy to write integration tests against your REST APIs. It uses the groovy HttpBuilder and is really simple.

Very cool, thanks.

Thanks this is great!

I have a suggestion for a couple of additional options.

1: sort {} members alphabetically. E.g.: {“b”:1,”a”:2} becomes {“a”:2,”b”:1}
2: sort {} members by complexity. E.g.:
{“a”:{},”b”:[],”c”:1} becomes {“c”:1,”b”:[],”c”:{}}

If using both options, I would expect 2 to take precendence over 1.

I think this would make it easier to understand the structure, and to find stuff in large blocks of json.

Thanks for writing this plugin, just what I was looking for!

Hi Richard,

I’m glad you like it, and I really like your suggestions! However, at the moment I’m a bit short on time, and especially option 2 seems a bit harder to implement. If you want to go for it: the plugin is open source, and I wouldn’t mind to release any changes you made to the plugin, so others can benefit from it too!

I get this error during intellij IDEA startup – version 8.1.2. I upgraded from 8.1 and the JSONFormatter plugin was installed before the upgrade

Is this an IDEA bug or just a bad install of the plugin?
ntlr/ANTLRException: antlr/ANTLRException
java.lang.NoClassDefFoundError: antlr/ANTLRException
at net.javaisp.intellij.plugin.jsonformatter.gui.JsonFormatPanelData.(
at net.javaisp.intellij.plugin.jsonformatter.JsonFormatterProjectComponent.initToolWindow(
at net.javaisp.intellij.plugin.jsonformatter.JsonFormatterProjectComponent.projectOpened(
at com.intellij.openapi.project.impl.ProjectImpl.c(
at com.intellij.openapi.project.impl.ProjectImpl.access$300(
at com.intellij.openapi.project.impl.ProjectImpl$MyProjectManagerListener.projectOpened(
at com.intellij.openapi.project.impl.ProjectManagerImpl$2.projectOpened(
at com.intellij.openapi.project.impl.ProjectManagerImpl.d(
at com.intellij.openapi.project.impl.ProjectManagerImpl.openProject(
at com.intellij.openapi.project.impl.ProjectManagerImpl.loadAndOpenProject(
at com.intellij.openapi.project.impl.ProjectManagerImpl.loadAndOpenProject(
at com.intellij.ide.impl.ProjectUtil.openProject(
at com.intellij.ide.RecentProjectsManager.doOpenProject(
at com.intellij.ide.RecentProjectsManagerBase$MyAppLifecycleListener.appStarting(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at com.intellij.util.messages.impl.MessageBusConnectionImpl.deliverMessage(
at com.intellij.util.messages.impl.MessageBusImpl.doPumpMessages(
at com.intellij.util.messages.impl.MessageBusImpl.pumpMessages(
at com.intellij.util.messages.impl.MessageBusImpl.sendMessage(
at com.intellij.util.messages.impl.MessageBusImpl.access$000(
at com.intellij.util.messages.impl.MessageBusImpl$2.invoke(
at $Proxy36.appStarting(Unknown Source)
at com.intellij.idea.IdeaApplication.b(
at com.intellij.idea.IdeaApplication.access$400(
at com.intellij.idea.IdeaApplication$IdeStarter$
at com.intellij.openapi.application.impl.LaterInvocator$
at java.awt.event.InvocationEvent.dispatch(
at java.awt.EventQueue.dispatchEvent(
at com.intellij.ide.IdeEventQueue.c(
at com.intellij.ide.IdeEventQueue.b(
at com.intellij.ide.IdeEventQueue.dispatchEvent(
at java.awt.EventDispatchThread.pumpOneEventForFilters(
at java.awt.EventDispatchThread.pumpEventsForFilter(
at java.awt.EventDispatchThread.pumpEventsForHierarchy(
at java.awt.EventDispatchThread.pumpEvents(
at java.awt.EventDispatchThread.pumpEvents(
Caused by: java.lang.ClassNotFoundException: antlr.ANTLRException
at java.lang.ClassLoader.loadClass(
at java.lang.ClassLoader.loadClassInternal(
… 40 more

It reports “Invalid JSON: line 1:21: unexpected char: ‘E'” for the following json (which is valid):

{“energyLevel”: 1.05E-4}

Thanks 🙂

Hi Marc, thanks for the report, but I no longer maintain the project. If you want to fix it, go ahead, and I’ll release it.

Hi Erik,

Yes, I noticed that most comments were from back in 2009, so I figured it’s not actively maintained. No worries.


Thanks to the guy who said TextMate can do it. That worked for me.
I would like to install this but the instructions are a little light for me: I have not installed a plugin before, I do not find it in the IDE Manager, I see no “source repo” here to add so that I can select it. So one day if and when I have time, I will install.

Meantime a few sentences beyond “use the plug in manager” might to get us problem children started faster. Of get it listed such that searching for JSON makes it available…

After installing the plugin, where is it in the IDE? Should I look for it in a menu, or in a window, or where?

Is this plugin still working with phpStom 7.3.1? Is there a anykind of documentation?

Where's The Comment Form?

Liked it here?
Why not try sites on the blogroll...

%d bloggers like this: