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

For clean json dump python output, I swear by `indent=2` and `sort_keys=True`.

But if you’re lazy (like me), just use `json.dumps(data, indent=4)` and call it a day.

Also, Chrome’s dev tools format json automatically if you paste it into the console. Handy for quick checks!

---

Wow, thanks for all the awesome tips! I tried `indent=4` and `ensure_ascii=False`, and it’s way cleaner now.

Didn’t know about `orjson`—gonna check that out next. Also, the `json.tool` trick is gold.

One follow-up: Does `orjson` work the same way with files, or is it just for dumps?

Thanks again, y’all rock! 🚀

Messages In This Thread



Users browsing this thread: 1 Guest(s)