How to format pasted JSON in IntelliJ / Android Studio

Daniel Wilson picture Daniel Wilson · Dec 13, 2016 · Viewed 75.2k times · Source

I often need to use a text editor while writing code to paste random notes but especially JSON responses, where I format them using a plugin (for Sublime).

I recently heard about the 'scratch file' feature in IntelliJ / Android Studio which does exactly what I need it to - except I can't make it format JSON I paste in nicely.

How can I make Android Studio format JSON in a scratch buffer file?

Answer

Jason D picture Jason D · Mar 27, 2018

I highlight the code and run Command Option L (a short-cut for the Code->Reformat Code menu).

Note that this only works if the code is well-formed JSON (clear any red squiggles).