[py 2.7] JSON and UTF-8

dieter dieter at handshake.de
Fri Sep 30 02:33:00 EDT 2016


Gilmeh Serda <gilmeh.serdah at nothing.here.invalid> writes:

> Is there something that can be done when writing JSON using its dump/
> dumps feature so, e.g. Cyrillic text will show up correctly in a text 
> editor afterwards?
> ...
> The 'template.json' contains this:
>
> {
>     "test": "øæßþåнайтеĦŒŒ®®®"
> }
>
> What the json module outputs to the 'output.json' file is:
>
> {"test": "\u00f8\u00e6\u00df\u00fe\u00e5\u043d\u0430\u0439\u0442\u0435
> \u0126\u0152\u0152\u00ae\u00ae\u00ae"}
>
> But I would really like to be able to read that.

The "dumps" function has a parameter which allows the use
of unicode (instead of ascii encoded) strings.
Likely, using this parameter will solve your problem.


I have found out that some browsers have problems with some
unicode characters. Maybe, this is one reason to have
ascii encoded strings the default for "dumps".




More information about the Python-list mailing list