python - JSON dump breaks my dictionary when using certain characters -
dumping data file json.dump. data looks this:
{"hello": {"this": 1, "a": 1, "is": 1, "test": 1}}
the code use achieve follows (worddict file, file.json):
with open(words, 'w') fp: json.dump(worddict, fp) fp.close()
i'd have data in format:
{ "hello": { "a": 1, "is": 1, "test": 1, "this": 1 }
i changed code this:
with open(words, 'w') fp: json.dump(worddict, fp, sort_keys=true, indent=4, separators=(',', ': ')) fp.close()
and works, until try dump characters "Á", "É", "Ű"... these characters breaks worddict file, , when cat file looks this:
{
any idea why?
replace
json.dump(worddict, fp, sort_keys=true, indent=4, separators=(',', ': '))
with
json.dump(worddict, fp, sort_keys=true, indent=4, separators=(',', ': '), ensure_ascii=false)
Comments
Post a Comment