Python json : do NOT use ensure_ascii with the dump(s) method

ensure_ascii=False is evil! It does results in unicode, but with a character set that is different from 'utf8', even if you also pass encoding='utf8'. So always use the encoding parameter instead !!

So, do this:
json_string = json.dumps(obj = json_obj, indent = 2, encoding="utf8")
Not that:
json_string = json.dumps(obj = json_obj, ensure_ascii = False, indent = 2, encoding="utf8")

Comments

Popular posts from this blog

Handling control characters (escaping) in python for json and mysql

python port sniffer with pcapy and impacket

Django field, form and model validation process