Another Python Unicode Fiasco on JSON
It’s a re-post of my comment here: 1
Basically, I think there is a bug in the json.dump()
function in Python 2 (only) - It can’t dump a Python (dictionary / list) data containing non-ASCII characters, even you open the file with the encoding = 'utf-8'
parameter. (i.e. no matter what you do). However, json.dump()
works fine on Python 3 and json.dumps()
works on both Python 2 and 3.
The following code breaks in Python 2 with exception TypeError: must be unicode, not str
(Python 2.7.6, Debian):
It, however, works fine in Python 3.
The following stroke-out statements are wrong, so just ignore them.