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 gregory.p.smith
Recipients barry, chrism, eric.araujo, gregory.p.smith, ncoghlan, pitrou, serhiy.storchaka, terry.reedy
Date 2013-12-08.08:55:30
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1386492930.73.0.287088649801.issue19837@psf.upfronthosting.co.za>
In-reply-to
Content
upstream simplejson (of which json is an earlier snapshot of) has an encoding parameter on its dump and dumps method.  Lets NOT break compatibility with that API.

Our users use these modules interchangeably today, upgrading from stdlib json to simplejson when they need more features or speed without having to change their code.

simplejson's dumps(encoding=) parameter tells the module what encoding to decode bytes objects found within the data structure as (whereas Python 3.3's builtin json module being older doesn't even support that use case and raises a TypeError when bytes are encountered within the structure being serialized).

http://simplejson.readthedocs.org/en/latest/

A json.dump_bytes() function implemented as:

def dump_bytes(*args, **kwargs):
  return dumps(*args, **kwargs).encode('utf-8')

makes some sense.. but it is really trivial for anyone to write that .encode(...) themselves.

a dump_bytes_to_file method that acts like dump() and calls .encode('utf-8') on all str's before passing them to the write call is also doable... but it seems easier to just let people use an existing io wrapper to do that for them as they already are.

As for load/loads, it is easy to allow that to accept bytes as input and assume it comes utf-8 encoded.  simplejson already does this.  json does not.
History
Date User Action Args
2013-12-08 08:55:30gregory.p.smithsetrecipients: + gregory.p.smith, barry, terry.reedy, chrism, ncoghlan, pitrou, eric.araujo, serhiy.storchaka
2013-12-08 08:55:30gregory.p.smithsetmessageid: <1386492930.73.0.287088649801.issue19837@psf.upfronthosting.co.za>
2013-12-08 08:55:30gregory.p.smithlinkissue19837 messages
2013-12-08 08:55:30gregory.p.smithcreate