What's the best way to use json dump in Python for clean data output? or How do I properly format a j

16 Replies, 999 Views

For real tho, json dump python defaults are ugly af.

Here’s my go-to setup:
```python
json.dumps(data, indent=2, ensure_ascii=False, separators=(',', ': '))
```

The `separators` tweak adds a space after colons, which makes it even cleaner.

Also, if you’re dumping to a file, `json.dump()` with the same params works great.

Messages In This Thread



Users browsing this thread: 1 Guest(s)