This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Michael.Kuss
Recipients Michael.Kuss, ezio.melotti, vstinner
Date 2014-10-22.18:55:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1414004123.6.0.971106689488.issue22701@psf.upfronthosting.co.za>
In-reply-to
Content
When running the following:

>> json.dump(['name': "港区"], myfile.json, indent=4, separators=(',', ': '), ensure_ascii=False)

the function escapes the unicode, even though I have explicitly asked to not force to ascii:
\u6E2F\u533A

By changing "__init__.py" such that the fp.write call encodes the text as utf-8, the output json file displays the human-readable text required (see below).


OLD (starting line 167):

if (not skipkeys and ensure_ascii and
        check_circular and allow_nan and
        cls is None and indent is None and separators is None and
        encoding == 'utf-8' and default is None and not kw):
        iterable = _default_encoder.iterencode(obj)
    else:
        if cls is None:
            cls = JSONEncoder
        iterable = cls(skipkeys=skipkeys, ensure_ascii=ensure_ascii,
            check_circular=check_circular, allow_nan=allow_nan, indent=indent,
            separators=separators, encoding=encoding,
            default=default, **kw).iterencode(obj)
for chunk in iterable:
    fp.write(chunk)


NEW:

if (not skipkeys and ensure_ascii and
        check_circular and allow_nan and
        cls is None and indent is None and separators is None and
        encoding == 'utf-8' and default is None and not kw):
        iterable = _default_encoder.iterencode(obj)
        for chunk in iterable:
            fp.write(chunk)
    else:
        if cls is None:
            cls = JSONEncoder
        iterable = cls(skipkeys=skipkeys, ensure_ascii=ensure_ascii,
            check_circular=check_circular, allow_nan=allow_nan, indent=indent,
            separators=separators, encoding=encoding,
            default=default, **kw).iterencode(obj)
        for chunk in iterable:
            fp.write(chunk.encode('utf-8'))
History
Date User Action Args
2014-10-22 18:55:23Michael.Kusssetrecipients: + Michael.Kuss, vstinner, ezio.melotti
2014-10-22 18:55:23Michael.Kusssetmessageid: <1414004123.6.0.971106689488.issue22701@psf.upfronthosting.co.za>
2014-10-22 18:55:23Michael.Kusslinkissue22701 messages
2014-10-22 18:55:23Michael.Kusscreate