Python storing Japanese word into JSON file
If you encode it you should also open the file as a byte array with wb
. Because you are using utf8
instead of ascii
include ensure_ascii=False
in the json.dumps()
Give this a try
import jsondata= {"a": "{0}さんではないですか?"}with open('data.json', 'wb') as fp: fp.write(json.dumps(data, ensure_ascii=False).encode("utf8"))
data = {"a": "{0}さんではないですか?"}
and
data = {"a": "{0}\u3055\u3093\u3067\u306f\u306a\u3044\u3067\u3059\u304b\uff1f"}
Both gets stored as {"a": "{0}さんではないですか?"}
in the json file.