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

16 Replies, 2279 Views

Hey! You're almost there with `indent=None` and `separators=(',', ':')`. Just make sure you're not accidentally passing any other arguments that might add formatting.

Try this:
```python
import json
data = {"key": "value"}
print(json.dumps(data, indent=None, separators=(',', ':')))
```
This should give you json dumps without newlines. If it doesn't, double-check your code for any extra params.

Also, check out [jsonformatter.curiousconcept.com](https://jsonformatter.curiousconcept.com) for quick JSON formatting tools.

Messages In This Thread



Users browsing this thread: 1 Guest(s)