Format JSON String From IntelliJ IDEA

How many countless times must I have found myself with a piece of JSON string that is formatted in a way that makes it very hard for me to read. Perhaps you’ve also experienced this several times too?

As a back-end developer, having to deal with a lot of JSON is unavoidable. Heck, I deal with it on a daily basis for years now. So if a JSON object is returned as one very long line, getting the necessary information out of it by eye becomes very hard to do. Yeah, minification can be both good and bad.

Lightweight Options – Others

My go to lightweight JSON formatting tool would be Gedit on Ubuntu/Linux. It has the basic means to do that, though I must say it might not be a default functionality, I may have added it manually or via a plugin. Go to and check if you have it at: Tools > External Tools > Format JSON
(If it is not there I will write about it in a different post soon. Here you go: https://www.joseyamut.xyz/2020/11/20/offline-json-formatter/)

On Windows, the ubiquitous Notepad++ does the job as well. I had to add a plugin albeit. Better handling of JSON with a few other functionalities, depending on the plugin. Can’t remember exactly where and how right now. I’m not on my Windows desktop, but Google would be more than enough to get you going should you opt for this route.

Then of course anyone who’s ever worked with RESTful APIs know about this awesome, super handy, multi-platform developer tool named Postman. Who hasn’t? It runs on Linux, Windows and MacOS. It too can format JSON. It even can fold down to the objects and arrays so it becomes easier to read the entire JSON, especially large ones. There’s some limited color-coding too.

When none of the above are readily available, I usually have this handy link off the top of my head for an online third-party JSON formatting tool, but I shall not mention it here. Pretty basic. Just a single page, paste your JSON string in there and hit format. Done! Now the string becomes more human-readable and friendly to my eyes. It’s fast-ish too and can handle large JSON objects.

The thing is, 3rd party online formatting tools might not be a great way especially when you’re dealing with sensitive information. Even if it’s just for mock testing I would definitely stay away from it. Who knows, everything you throw there is getting logged on their servers, right? (I’m almost certain!)

So one other way that you can use on multiple platforms is through IntelliJ IDE. Yes, if you use this excellent piece of development software as your daily driver, then you can most certainly make use of this feature that you perhaps did not know existed or are not taking advantage of. No need to use another application.

Use Scratch File – IntelliJ IDEA

(1) On IntelliJ IDE, go to: File > New > Scratch File
Shortcut key combo: Ctrl + Alt + Shift + Insert

(2) A popup box will come out with a list of file types.

(3) Scroll down and choose JSON.

The default name of this scratch file when created is scratch.json, then scratch_1.json for the next one, and so on.

(4) Put your JSON string in there.

(5) Navigate to: Code > Reformat Code
Shortcut key combo: Ctrl + Alt + L
Fair warning: On Ubuntu 16.04 that is the ‘Lock Desktop’ key combination so don’t get surprised when something else happens.

And, presto! Formatted JSON right before you. The resulting formatted JSON is collapsible. Also is color-coded. The example below does not show both, but it does. You’ll just have to try it to believe it. See for yourself.

From this:

{ "hello" : "world", "foo"  : "bars" }

To this:

{
  "hello": "world",
  "foo": "bars"
}

Magic? Nope, just IntelliJ. That’s why I love this IDE. 😍

Similar Posts:

How many countless times must I have found myself with a piece of JSON string that is formatted in a way that makes it very hard for me to read. Perhaps you’ve also experienced this several times too? As a back-end developer, having to deal with a lot of JSON is unavoidable. Heck, I deal…