Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python storing Japanese word into JSON file

I've the json data in below format and I'm trying to store it in JSON file but it's storing in encoded form in data.json file

data= {"a": "{0}さんではないですか?"}
    with open('data.json', 'w') as fp:
        fp.write(json.dumps(data).encode("utf8"))

data.json

{"a": "{0}\u3055\u3093\u3067\u306f\u306a\u3044\u3067\u3059\u304b\uff1f"}

I want data.json to be in this format

{"a": "{0}さんではないですか?"}

I tried encoding it and then putting it in json file, no success.. can anybody tell what I'm doing wrong here and what is the right way?

like image 937
Gaurav Sharma Avatar asked May 12 '18 15:05

Gaurav Sharma


Video Answer


1 Answers

Try using json.dumps(s, ensure_ascii=False).

like image 147
Javier Avatar answered Oct 06 '22 23:10

Javier