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

22 Replies, 1704 Views

Hey folks,
So I was messing around with Python and trying to figure out how to use json dumps without newlines in a dictionary. Like, I want my JSON output to be compact, no extra spaces or line breaks, ya know?

I tried `json.dumps(my_dict)` but it adds all these newlines and indents by default. Annoying, right?
Turns out, you can just do `json.dumps(my_dict, separators=(',', ':'))` and it squishes everything together. No extra fluff!

Anyone else run into this? Or got a better way to get json dumps without newlines in a dictionary?
Thx in advance!

- A confused coder

Messages In This Thread
How to Use json.dumps Without Newlines in a Dictionary for Compact Output? - by - 12-02-2025, 06:25 AM



Users browsing this thread: 1 Guest(s)