Aaron Hall <[email protected]> added the comment:
>From a design standpoint, I'm fairly certain the sort_keys argument was
>created due to Python's dicts being arbitrarily ordered.
Coercing to strings before sorting is unsatisfactory because, e.g. numbers sort
lexicographically instead of by numeric value when strings.
>>> import json
>>> json.dumps({i:i**2 for i in range(15)}, sort_keys=True)
'{"0": 0, "1": 1, "2": 4, "3": 9, "4": 16, "5": 25, "6": 36, "7": 49, "8": 64,
"9": 81, "10": 100, "11": 121, "12": 144, "13": 169, "14": 196}'
>>> json.dumps({str(i):i**2 for i in range(15)}, sort_keys=True)
'{"0": 0, "1": 1, "10": 100, "11": 121, "12": 144, "13": 169, "14": 196, "2":
4, "3": 9, "4": 16, "5": 25, "6": 36, "7": 49, "8": 64, "9": 81}'
Changing the order of operations is just going to create more issues, IMHO.
Now that users can sort their dicts prior to providing them to the function,
e.g.:
>>> json.dumps({str(i):i**2 for i in range(15)})
'{"0": 0, "1": 1, "2": 4, "3": 9, "4": 16, "5": 25, "6": 36, "7": 49, "8": 64,
"9": 81, "10": 100, "11": 121, "12": 144, "13": 169, "14": 196}'
we could deprecate the argument, or just keep it as-is for hysterical raisins.
Regardless, I'd close this as "won't fix".
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue25457>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com