json.dumps save some unicode chars as code, not char - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: json.dumps save some unicode chars as code, not char (/thread-11958.html) |
json.dumps save some unicode chars as code, not char - buran - Aug-02-2018 I use with open('docs_new.json', 'w') as f: f.write(json.dumps(my_json, indent=2))to write a json object to a file. Some chars are printed as unicode, not chars, e.g. \u201cCreate a new App\u201d instead of “Create a new App” Part of it was in the original json file and was correct, part of text comes from scraping a website. In both cases in the result file it writes the code. when I print my_json object, it looks ok. I'm stuck, what is wrong? Using python3.5, Linux Mint RE: json.dumps save some unicode chars as code, not char - buran - Aug-02-2018 OK, found it with open('docs_new.json', 'w') as f: f.write(json.dumps(my_json, indent=2, ensure_ascii=False)) |