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 josh.r
Recipients josh.r, tanzer@swing.co.at
Date 2015-10-23.02:56:30
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1445568990.87.0.9756037597.issue25457@psf.upfronthosting.co.za>
In-reply-to
Content
As a workaround (should you absolutely need to sort keys by some arbitrary criteria), you can initialize a collections.OrderedDict from the sorted items of your original dict (using whatever key function you like), then dump without using sort_keys=True. For example, your suggested behavior (treat all keys as str) could be achieved by the user by replacing:

    json.dumps(mydict, sort_keys=True)

with:

    json.dumps(collections.OrderedDict(sorted(mydict.items(), key=str)))

Particularly in 3.5 (where OrderedDict is a C builtin), this shouldn't incur too much additional overhead (`sort_keys` has to make a sorted list intermediate anyway), and the output is the same, without introducing implicit hiding of errors.
History
Date User Action Args
2015-10-23 02:56:30josh.rsetrecipients: + josh.r, tanzer@swing.co.at
2015-10-23 02:56:30josh.rsetmessageid: <1445568990.87.0.9756037597.issue25457@psf.upfronthosting.co.za>
2015-10-23 02:56:30josh.rlinkissue25457 messages
2015-10-23 02:56:30josh.rcreate