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

16 Replies, 2288 Views

Hmm, I think you’re missing the `ensure_ascii=False` flag if you’re dealing with non-ASCII characters. That might be messing with your output.

Try this:
```python
import json
data = {"name": "Jöhn"}
print(json.dumps(data, indent=None, separators=(',', ':'), ensure_ascii=False))
```
This should give you json dumps without newlines and handle special characters properly.

Messages In This Thread



Users browsing this thread: 1 Guest(s)