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 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. This time I’m pretty sure. 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.

When neither 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.

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: