Josh Rosenberg added the comment: 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. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue25457> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com