I'm working on some Python code for my local billiard hall and I'm running into problems with JSON encoding. When I dump my data into a file I obviously get all the data in a single line. However, I want my data to be dumped into the file following the format that I want. For example (Had to do picture to get point across), My custom JSON format . I've looked up questions on custom JSONEncoders but it seems they all have to do with datatypes that aren't JSON serializable. I never found a solution for my specific need which is having everything laid out in the manner that I want. Basically, I want all of the list elements to on a separate row but all of the dict items to be in the same row. Do I need to write my own custom encoder or is there some other approach I need to take? Thanks!
Asked
Active
Viewed 474 times
0
-
1. Why exactly is it a problem that it is all in one line? 2. Isn't this just a case of providing the `indent` parameter to [`json.dump`](https://docs.python.org/3.6/library/json.html#json.dump)? – UnholySheep Jun 30 '17 at 07:04
-
Possible duplicate of [How to Python prettyprint a JSON file](https://stackoverflow.com/questions/12943819/how-to-python-prettyprint-a-json-file) – Mel Jun 30 '17 at 07:06
-
Here is a similar question. Look at the accepted answer how to write encoder: https://stackoverflow.com/questions/16264515/json-dumps-custom-formatting – guma44 Jun 30 '17 at 07:05
-
have tried using the `indent=2` parameter? Try `json.dumps(
, indent = 2)` – Aman Singh Dec 24 '17 at 18:59