Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format pasted JSON in IntelliJ / Android Studio

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?

like image 689
Daniel Wilson Avatar asked Dec 13 '16 09:12

Daniel Wilson


People also ask

How do I beautify JSON in IntelliJ?

Usage: Paste JSON string into editor, and press Reformat Code (Ctrl + Alt + L in windows) to format code as if you editing a file with . json suffix. The plugin panel will appear on the right side of the window after installed, and you don't have to restart the IDE.

Can we format JSON in IntelliJ?

IntelliJ IDEA helps you work with JSON files — it checks their syntax and formatting. In popular types of configuration files, IntelliJ IDEA provides code completion, thanks to the JSON Schema, which is a special format for describing the structure and contents of such files.

How do I unformat a JSON file?

Formatting# You can format your JSON document using Ctrl+Shift+I or Format Document from the context menu.


1 Answers

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

On Windows use Ctrl Alt L.

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

like image 176
Jason D Avatar answered Sep 16 '22 11:09

Jason D