Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to compress code in .json file in IDEA?

IDEA makes the code in the .json file easier to read by adding appropriate line breaks and indentation, but I now want to ask IDEA to compress the JSON content to the extreme (without any indentation and line breaks). What should I do?

like image 382
goushiso Avatar asked Sep 09 '25 17:09

goushiso


2 Answers

With IntelliJ IDEA 2021.2.1 (Ultimate Edition) at least, you can simply do:

Select-All, Edit > Join Lines

(Windows: ctrl-A, ctrl-shift-J with default mapping.) This places everyting on one line, so no indentation or linebreaks. However, there will be a after commas and before/after colons, if your code style is set for that.

like image 114
mconner Avatar answered Sep 12 '25 07:09

mconner


IDEA doesn't have any built-in plugins for that. You can try the solutions available on the web, json-minify package, for example. It can then be set up as external tool or a file watcher to be run from the IDE

like image 30
lena Avatar answered Sep 12 '25 08:09

lena