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, 1005 Views

Yup, `indent` is the way to go for clean json dump python output. I usually set it to 2 or 4 depending on how nested the data is.

If you’re dealing with special chars, `ensure_ascii=False` is a must. Otherwise, it’ll escape everything.

Pro tip: Check out `json.tool` from the command line. Just pipe your json into it and it’ll prettify everything. Super handy!

```bash
python -m json.tool < messy.json > clean.json
```

Messages In This Thread



Users browsing this thread: 1 Guest(s)