Reputation: 483
I am falling on a problem, while dumping a chinese data (non-latin language data) into a json file.
I am trying to store list into a json
file with the following code;
with open("file_name.json","w",encoding="utf8") as file:
json.dump(edits,file)
It will dumped without any errors. When i am viewing a file, it will look like this,
[{sentence: \u5979\u7d30\u5c0f\u8072\u5c0d\u6211\u8aaa\uff1a\u300c\u6211\u501f\u4f60\u4e00\u679d\u925b\u7b46\u3002\u300d}...]
And I also tried out, without encoding option.
with open("file_name.json","w") as file:
json.dump(edits,file)
My question is, why my json file look like this, and how to dump my json file with having chinese string instead of unicode string. Any helps would be appreciated. Thanks : )
Upvotes: 0
Views: 1301
Reputation: 248
Check out the docs for json.dump.
Specifically, it has a switch ensure_ascii
that if set to False
should make the function not escape the characters.
If ensure_ascii is true (the default), the output is guaranteed to have all incoming non-ASCII characters escaped. If ensure_ascii is false, these characters will be output as-is.
Upvotes: 2