jsonContent = json.dumps(myDict, default=convert)
with open('data.json', 'w', encoding='utf-8') as f:
json.dump(jsonContent, f, ensure_ascii=False, indent=4)
return jsonContent
I am doing this to convert a dictionary to json and save it in a file. If I try to print the json with Python, I get an unformatted dict like this:
myDict = {'first': {'phone': 1900, 'desktop': 1577, 'tablet': 148, 'bot': 9, 'other': 1}},
This is still okay. But when I open the file, I see something like this:
"{\"first\": {\"phone\": 1900, \"desktop\": 1577, \"tablet\": 148, \"bot\": 9, \"other\": 1}´}"
How can I remove all the backslashes and format it properly in both, Python and the saved file?