Adding linebreak to json written by Python Adding linebreak to json written by Python json json

Adding linebreak to json written by Python


From this answer try outputdict = json.dumps(outputdict, indent=4) with the number of spaces you want to indent.


It sounds like its a 'Carriage Return' + 'Newline' issue which will cause the file to open as one long line in a Windows text editor.

Try:

with open("filename.json",'w', newline='\r\n') as f:

or:

with open("filename.json",'w', newline='\n') as f:

or there may even be a setting in your Text Editor to correct this issue.