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 ncoghlan
Recipients barry, chrism, cvrebert, eric.araujo, ezio.melotti, gregory.p.smith, jleedev, kdwyer, martin.panter, ncoghlan, pitrou, serhiy.storchaka, socketpair, terry.reedy, vstinner
Date 2016-08-01.08:17:32
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1470039453.66.0.0129832315681.issue19837@psf.upfronthosting.co.za>
In-reply-to
Content
I'm currently migrating a project that predates requests, and ended up needing to replace several "json.loads" calls with a "_load_json" helper that is just an alias for json.loads in Python 2, and defined as this in Python 3:

    def _load_json(data):
        return json.loads(data.decode())

To get that case to "just work", all I would have needed is for json.loads to accept bytes input, and assume it is UTF-8 encoded, that same way simplejson does. Since there aren't any type ambiguities associated with that, I think it would make sense for us to go ahead and implement at least that much for Python 3.6.

By contrast, if I'd been doing *encoding*, I don't think there's anything the Python 3 standard library could have changed *on its own* to make things just work - I would have needed to change my code somehow.

However, a new "dump_bytes" API could still be beneficial on that front as long as it was also added to simplejson: code that needed to run in the common Python 2/3 subset could use "simplejson.dump_bytes", while 3.6+ only code could just use the standard library version.

Having dump_bytes() next to dumps() in the documentation would also provide a better hook for explaining the difference between JSON-as-text-encoding (with "str" output) and JSON-as-wire-encoding (with "bytes" output after encoding the str representation as UTF-8).

In both cases, I think it would make sense to leave the non-UTF-8 support to simplejson and have the stdlib version be UTF-8 only.
History
Date User Action Args
2016-08-01 08:17:33ncoghlansetrecipients: + ncoghlan, barry, terry.reedy, gregory.p.smith, chrism, pitrou, vstinner, kdwyer, ezio.melotti, eric.araujo, cvrebert, socketpair, martin.panter, serhiy.storchaka, jleedev
2016-08-01 08:17:33ncoghlansetmessageid: <1470039453.66.0.0129832315681.issue19837@psf.upfronthosting.co.za>
2016-08-01 08:17:33ncoghlanlinkissue19837 messages
2016-08-01 08:17:32ncoghlancreate