7

For example:

>>> print(json.dumps('růže'))
"r\u016f\u017ee"

(Of course, in the real program it's not just a single string, and it also appears like this in the file, when using json.dump()) I'd like it to output simply "růže" as well, how to do that?

metatoaster
  • 17,419
  • 5
  • 55
  • 66
Theon144
  • 87
  • 1
  • 5

1 Answers1

14

Pass the ensure_ascii=False argument to json.dumps:

>>> print(json.dumps('růže', ensure_ascii=False))
"růže"
metatoaster
  • 17,419
  • 5
  • 55
  • 66
BrenBarn
  • 242,874
  • 37
  • 412
  • 384
  • 1
    This works! Except that since I was serializing and object, I had to convert the unicode strings with `.encode('utf-8')` first, otherwise it threw `UnicodeEncodeError` errors. Thanks! – Theon144 Jun 02 '12 at 19:45