Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get PyCharm to format a JSON file

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?

like image 521
Bruce Avatar asked Sep 27 '19 06:09

Bruce


People also ask

How do I format a JSON file?

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

How do I read a JSON file in Python?

Reading From JSON Python has a built-in package called json, which can be used to work with JSON data. It's done by using the JSON module, which provides us with a lot of methods which among loads() and load() methods are gonna help us to read the JSON file.


1 Answers

Ah, it doesn't auto-format it. If I paste in non-formatted JSON, it stays non-formatted. But if I press alt + cmd + L on Mac, Ctrl + Alt + L on windows, it formats it nicely.

like image 150
Bruce Avatar answered Sep 20 '22 11:09

Bruce