[issue21650] add json.tool option to avoid alphabetic sort of fields
Roundup Robot added the comment: New changeset 58a871227e5b by Berker Peksag in branch 'default': Issue #21650: Add an `--sort-keys` option to json.tool CLI. https://hg.python.org/cpython/rev/58a871227e5b -- nosy: +python-dev ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21650 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21650] add json.tool option to avoid alphabetic sort of fields
Berker Peksag added the comment: Thanks for the reviews. -- resolution: - fixed stage: commit review - resolved status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21650 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21650] add json.tool option to avoid alphabetic sort of fields
Raymond Hettinger added the comment: The patch looks good. One nit, the phrase sorted by their key has an odd ring to it and is mildly confusing, though technically correct. Perhaps, sorted alphabetically by key would be better for most folks. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21650 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21650] add json.tool option to avoid alphabetic sort of fields
Changes by Serhiy Storchaka storch...@gmail.com: -- assignee: - berker.peksag ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21650 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21650] add json.tool option to avoid alphabetic sort of fields
Changes by Berker Peksag berker.pek...@gmail.com: Added file: http://bugs.python.org/file37119/issue21650_v4.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21650 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21650] add json.tool option to avoid alphabetic sort of fields
Serhiy Storchaka added the comment: LGTM. -- stage: patch review - commit review ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21650 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21650] add json.tool option to avoid alphabetic sort of fields
Berker Peksag added the comment: Thanks for the suggestions. If you mean preserve order by default, then yes that would be a nice default. issue21650_v3.diff implements this idea. -- Added file: http://bugs.python.org/file37110/issue21650_v3.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21650 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21650] add json.tool option to avoid alphabetic sort of fields
Raymond Hettinger added the comment: To me, --unsorted implies arbitrary ordering such as the order generated by regular dictionaries. I think the option should be --order-preserving or some such. The option name needs to make it clear that the output is in the same order an the input. As side from the option name, I'm +1 on the patch. It is very annoying to look at scrambled JSON when the original presentation order made more logical sense. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21650 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21650] add json.tool option to avoid alphabetic sort of fields
Serhiy Storchaka added the comment: May be make sorting keys not default? -- nosy: +serhiy.storchaka ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21650 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21650] add json.tool option to avoid alphabetic sort of fields
Raymond Hettinger added the comment: Maybe make sorting keys not default? If you mean preserve order by default, then yes that would be a nice default. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21650 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21650] add json.tool option to avoid alphabetic sort of fields
Changes by Martin Panter vadmium...@gmail.com: -- nosy: +vadmium ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21650 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21650] add json.tool option to avoid alphabetic sort of fields
Berker Peksag added the comment: Updated patch attached based on feedback from David. Thanks! -- stage: needs patch - patch review Added file: http://bugs.python.org/file35631/issue21650_v2.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21650 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21650] add json.tool option to avoid alphabetic sort of fields
Pavel Kazlou added the comment: The idea is to keep the same order as in input. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21650 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21650] add json.tool option to avoid alphabetic sort of fields
R. David Murray added the comment: Yes but the input is turned into a dict, and dicts do not preserve order. Further, what is passed to the object_hook is already a dict, so the order is already lost before object_hook is called. Since the parser (or at least the Python version of the parser) first turns the input into a list of pairs, and a Python OrderedDict can be instantiated from a list of pairs, it would theoretically be possible to extend the object_hook API to allow an OrderedDict to be used on decode. Exactly how to do that so as to retain backward compatibility is a bit of a question. So, it is *possible* to achieve your aim, but it isn't as simple as allowing sort= to be set False. IMO being able to preserve the order of the input when desired (ie: use an OrderedDict object_hook) would be a nice feature to have. -- stage: patch review - needs patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21650 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21650] add json.tool option to avoid alphabetic sort of fields
R. David Murray added the comment: Wait, I read the code wrong. You can define object_pairs_hook, and use that to return an OrderedDict. So it should be possible to do this without changing the json module itself. This is actually documented as a place to use OrderedDict. Guess I should have read the docs instead of the code :) -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21650 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21650] add json.tool option to avoid alphabetic sort of fields
Antoine Pitrou added the comment: I don't really understand the point of this. The unsorted output order will be unpredictable for the user (it isn't necessarily the same as the order of fields in the input data). -- nosy: +ezio.melotti, pitrou, rhettinger ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21650 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21650] add json.tool option to avoid alphabetic sort of fields
R. David Murray added the comment: It should be possible to also change the tool to use OrderDicts, though. -- nosy: +r.david.murray ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21650 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21650] add json.tool option to avoid alphabetic sort of fields
R. David Murray added the comment: Or does the data get decoded to a dict *before* it gets passed to the object_hook? Probably, in which case nevermind... -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21650 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21650] add json.tool option to avoid alphabetic sort of fields
New submission from Pavel Kazlou: Currently when you use json.tool, fields are reordered alphabetically. In source code the value of sort_keys is hardcoded to be true. It should be easy to expose this option as command line parameter. -- components: Library (Lib) messages: 219675 nosy: Pavel.Kazlou priority: normal severity: normal status: open title: add json.tool option to avoid alphabetic sort of fields type: enhancement versions: Python 2.7 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21650 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21650] add json.tool option to avoid alphabetic sort of fields
Pavel Kazlou added the comment: This is the line in module I'm talking about: json.dump(obj, outfile, sort_keys=True, indent=4) -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21650 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21650] add json.tool option to avoid alphabetic sort of fields
Berker Peksag added the comment: Here's a patch with a test case. -- keywords: +patch nosy: +berker.peksag stage: - patch review versions: +Python 3.5 -Python 2.7 Added file: http://bugs.python.org/file35468/issue21650.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21650 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com