Python Forum

Full Version: json.dumps save some unicode chars as code, not char
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
OK, found it
with open('docs_new.json', 'w') as f:
    f.write(json.dumps(my_json, indent=2, ensure_ascii=False))