Why does json.dumps() encode emojis into unicode? See code and output below:
import json
obj = {"key": "hello 😀"}
print(obj)
{'key': 'hello 😀'}
print(json.dumps(obj))
'{"key": "hello \ud83d\ude00"}'
I have tried print(json.dumps(obj)).encode('utf-8') and some variants (.decode()...) but it didn't change the output much. Im working on Python 3.6.1
print(json.dumps(obj, ensure_ascii=False))
However, the ASCII variant is more portable, since you are almost guaranteed you won't have encoding problems. Docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With