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!

Advertisements

Make a Comment

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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.

http://jlorenzen.blogspot.com/2009/01/testing-rest-services-with-groovy.html

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.(JsonFormatPanelData.java:44)
at net.javaisp.intellij.plugin.jsonformatter.JsonFormatterProjectComponent.initToolWindow(JsonFormatterProjectComponent.java:62)
at net.javaisp.intellij.plugin.jsonformatter.JsonFormatterProjectComponent.projectOpened(JsonFormatterProjectComponent.java:44)
at com.intellij.openapi.project.impl.ProjectImpl.c(ProjectImpl.java:10)
at com.intellij.openapi.project.impl.ProjectImpl.access$300(ProjectImpl.java:35)
at com.intellij.openapi.project.impl.ProjectImpl$MyProjectManagerListener.projectOpened(ProjectImpl.java:6)
at com.intellij.openapi.project.impl.ProjectManagerImpl$2.projectOpened(ProjectManagerImpl.java:16)
at com.intellij.openapi.project.impl.ProjectManagerImpl.d(ProjectManagerImpl.java:194)
at com.intellij.openapi.project.impl.ProjectManagerImpl.openProject(ProjectManagerImpl.java:354)
at com.intellij.openapi.project.impl.ProjectManagerImpl.loadAndOpenProject(ProjectManagerImpl.java:365)
at com.intellij.openapi.project.impl.ProjectManagerImpl.loadAndOpenProject(ProjectManagerImpl.java:80)
at com.intellij.ide.impl.ProjectUtil.openProject(ProjectUtil.java:68)
at com.intellij.ide.RecentProjectsManager.doOpenProject(RecentProjectsManager.java:5)
at com.intellij.ide.RecentProjectsManagerBase$MyAppLifecycleListener.appStarting(RecentProjectsManagerBase.java:0)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.util.messages.impl.MessageBusConnectionImpl.deliverMessage(MessageBusConnectionImpl.java:101)
at com.intellij.util.messages.impl.MessageBusImpl.doPumpMessages(MessageBusImpl.java:182)
at com.intellij.util.messages.impl.MessageBusImpl.pumpMessages(MessageBusImpl.java:174)
at com.intellij.util.messages.impl.MessageBusImpl.sendMessage(MessageBusImpl.java:166)
at com.intellij.util.messages.impl.MessageBusImpl.access$000(MessageBusImpl.java:40)
at com.intellij.util.messages.impl.MessageBusImpl$2.invoke(MessageBusImpl.java:106)
at $Proxy36.appStarting(Unknown Source)
at com.intellij.idea.IdeaApplication.b(IdeaApplication.java:61)
at com.intellij.idea.IdeaApplication.access$400(IdeaApplication.java:9)
at com.intellij.idea.IdeaApplication$IdeStarter$3.run(IdeaApplication.java:14)
at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.run(LaterInvocator.java:16)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at com.intellij.ide.IdeEventQueue.c(IdeEventQueue.java:35)
at com.intellij.ide.IdeEventQueue.b(IdeEventQueue.java:99)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:217)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Caused by: java.lang.ClassNotFoundException: antlr.ANTLRException
at com.intellij.ide.plugins.cl.PluginClassLoader.loadClass(PluginClassLoader.java:54)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
… 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.

Cheers,
M

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…
Thanks

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: