How to Use json.dumps Without Newlines in a Dictionary for Compact Output?

22 Replies, 1715 Views

I’ve been using `json.dumps(my_dict, separators=(',', ':'))` for years. It’s the most efficient way to get json dumps without newlines in a dictionary. If you’re working with APIs, Postman also has a “raw” JSON mode that strips out all formatting.
Thanks for the tip! I was struggling with this too. For json dumps without newlines in a dictionary, your solution is perfect. I also found that using `json.dumps(my_dict, indent=None)` works similarly. For quick JSON validation, I use [jsonformatter.curiousconcept.com](https://jsonformatter.curiousconcept.com).



Users browsing this thread: 1 Guest(s)