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

16 Replies, 2070 Views

Hey, I feel your pain! JSON formatting can be a headache. For json dumps without newlines, try this:

```python
import json
data = {"key1": "value1", "key2": "value2"}
compact_json = json.dumps(data, indent=None, separators=(',', ':'))
print(compact_json)
```

If it’s still not working, maybe your environment is adding extra formatting. Try running it in a different editor or terminal.

Messages In This Thread



Users browsing this thread: 1 Guest(s)