I am trying to dump a json content like:
foo = simplejson.dumps(data)
But I am seeing the following error:
UnicodeDecodeError: 'utf8' codec can't decode byte 0xd6 in position 33: invalid continuation byte
How should I en/decode it properly ?
I am trying to dump a json content like:
foo = simplejson.dumps(data)
But I am seeing the following error:
UnicodeDecodeError: 'utf8' codec can't decode byte 0xd6 in position 33: invalid continuation byte
How should I en/decode it properly ?
Your data contains str
objects that contain non-UTF-8 bytes. All text in JSON is Unicode, so str
values are decoded to Unicode assuming UTF-8.
If that does not apply to all text in your data
, you either need to decode it to Unicode before dumping to JSON, or you need to tell the dumps()
function what codec to decode bytestrings with:
foo = simplejson.dumps(data, encoding='<codec for bytestrings in data>')