Skip to content

Instantly share code, notes, and snippets.

@jigi-33
Created November 2, 2021 13:15
Show Gist options
  • Save jigi-33/a887d272a9eb37bc4d2ad9ddf2ac7d27 to your computer and use it in GitHub Desktop.
Save jigi-33/a887d272a9eb37bc4d2ad9ddf2ac7d27 to your computer and use it in GitHub Desktop.
[trick] JSON pretty formatting in PyCharm and other IntelliJ IDEA products

JSON auto-formatting in PyCharm Community edition

Q:

When I create a .json file in PyCharm and put in some JSON, I'm expecting it to format it as per the format shown under File-> Settings-> Editor-> Code Style-> JSON.

But instead, my code stays as it is - e.g. more than one JSON key value pair on the same line, like this:

{"just a test": "does this work","this should format": "but it doesn't"}

How can I make it so that when I open a .json file with PyCharm, it's nicely formatted?

I have checked that .json files are associated in the Editor-> File types dialogue, and the editor tab correctly has the JSON icon, so PyCharm knows it's a JSON file.

Is there a key combination I have to hit to get it to format prettily or something?


A1:

My file is with .json extension for it. Then, i clicked on Code-> Reformate Code and then I see a pretty JSON!

A2:

PyCharm doesn't auto-format it, if I paste in open json-file non-formatted JSON, it stays non-formatted. But if I press Ctrl + Alt + L on PC, it formats it nicely!

@jigi-33
Copy link
Author

jigi-33 commented Feb 28, 2023

Thanks its work for me "Code-> Reformate Code"!!!

Enjoy Bro :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment