How can I force Python to stop writing my .json
file to one line? I've tried changing the write command with open('manifest.json', 'wb') as f:
to with open('manifest.json', 'w') as f:
but it is still writing to one line.
import json
with open('manifest.json', 'r') as f:
json_data = json.load(f)
json_data['server-version'] = "xxxx-x.x.x"
with open('manifest.json', 'w') as f:
f.write(json.dumps(json_data))
print('Successful.')
For pretty printing use indent parameter
print(json.dumps({'4': 5, '6': 7}, sort_keys=True, indent=4, separators=(',', ': ')))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With