Python (2.x) builtin json library supports encoding both unicode & utf-8 encoded (non-ASCII) strings - but apparently not at the same time. Try:
import json; json.dumps([u'Ä', u'Ä'.encode("utf-8")], ensure_ascii=False)
and see it raise a UnicodeDecodeError. Whereas both:
json.dumps([u'Ä'], ensure_ascii=False)
and
json.dumps([u'Ä'.encode("utf-8")], ensure_ascii=False)
...work ok.
Why does JSON encoding of data with both unicode & utf-8 encoded (non-ASCII) strings produce an UnicodeDecodeError? My Python site encoding is ASCII.
json.dumps(['Ä'.encode("utf-8")], ensure_ascii=False)
does not work ok. – luoluou'Ä'.encode("utf-8")
(note the u!) – RemcoGerlich