0

I've got a problem with encoding unicode escapes. After python manage.py dumpdata, I have json with escaped strings.

I need to get readable strings, so I tried to use

json_data.decode("unicode_escape").encode("utf8")

but decode("unicode_escape") also decodes symbols like \n, \" etc. And ofcourse I get not valid json.

How can I fix it?

Vladimir Solovyov
  • 287
  • 1
  • 2
  • 11
  • Could try `manage.py dumpdata --format=xml > output.xml`, which handles unicode correctly. That and other things to try found here: http://stackoverflow.com/questions/2137501/django-dumpdata-utf-8-unicode – dylrei Feb 04 '15 at 20:37
  • Oh, ofcourse, with xml everything is ok. But is any way do solve this problem with JSON? – Vladimir Solovyov Feb 04 '15 at 20:41
  • 1
    Can't say I've tried. I suppose you could update the dumpdata code. You'll probably need to do something along these lines: http://stackoverflow.com/questions/10865180/unicode-values-in-strings-are-escaped-when-dumping-to-json-in-python – dylrei Feb 04 '15 at 20:48
  • Thanks! `json.dumps(data, ensure_ascii=False)` works for me. – Vladimir Solovyov Feb 04 '15 at 21:09

0 Answers0