cannot output a json encoded dict containing accents (noob inside)

Posted by user296546 on Stack Overflow See other posts from Stack Overflow or by user296546
Published on 2010-05-01T13:46:47Z Indexed on 2010/05/01 13:57 UTC
Read the original article Hit count: 357

Filed under:
|
|

Hi all,

here is a fairly simple example wich is driving me nuts since a couple of days. Considering the following script:

# -*- coding: utf-8 -*
from json import dumps as json_dumps

machaine = u"une personne émérite"
print(machaine)

output = {}
output[1] = machaine
jsonoutput = json_dumps(output)
print(jsonoutput)

The result of this from cli:

une personne émérite
{"1": "une personne \u00e9m\u00e9rite"}

I don't understand why their such a difference between the two strings. i have been trying all sorts of encode, decode etc but i can't seem to be able to find the right way to do it. Does anybody has an idea ?

Thanks in advance. Matthieu

© Stack Overflow or respective owner

Related posts about python

Related posts about utf8