Title: Document json "sort_keys" parameter properly
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.2, Python 3.3, Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: asvetlov, chris.jerdonek, cvrebert, docs@python, ezio.melotti, godfryd, ncoghlan, petri.lehtinen, python-dev
Priority: normal Keywords: easy, patch

Created on 2012-04-13 02:42 by ncoghlan, last changed 2012-10-28 12:59 by asvetlov. This issue is now closed.

File name Uploaded Description Edit
json-sort-keys.patch godfryd, 2012-04-30 18:17
json.rst.patch cvrebert, 2012-09-01 22:13 b0rk-free docs patch review
json_init.patch cvrebert, 2012-09-01 22:20 b0rk-free code patch review
issue14570.diff cvrebert, 2012-10-28 08:15 revised patch review
issue14570-2.7.diff cvrebert, 2012-10-28 12:43 patch against 2.7 review
Messages (14)
msg158194 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2012-04-13 02:42
The json "sort_keys" parameter is actually supported as an argument to dump() and dumps() (and is used that way in the examples), but is only documented as an argument to the JSONEncoder constructor.
msg159539 - (view) Author: Michal Nowikowski (godfryd) Date: 2012-04-28 20:38
In json module there are dump/dumps methods which internally instantiate encoder class JSONEncoder (or some other user-defined encoder clas).
They look as follows:

json.dump(obj, fp, 


Some of dump/dumps arguments are passed to encoder class:
- skipkeys
- ensure_ascii
- check_circular
- allow_nan
- indent
- separators
- default

And it looks that sort_keys is just missing in keyword args in dump/dumps method.
But it still can be passed implicitly using **kw arg.

I would propose to do:
- add explicitly sort_keys keyword arg to dump/dumps methods
- add passing it to encoder class
- and adjust documentation accordingly.
msg159719 - (view) Author: Michal Nowikowski (godfryd) Date: 2012-04-30 18:17
Attached a patch.
To preserve current order of arguments in dumps/dump functions sort_keys argument has been added to the end of arguments just before **kw.
msg169189 - (view) Author: Chris Rebert (cvrebert) * Date: 2012-08-27 07:46
Erm, the patch seems to have some ANSI terminal coloring escape code junk (e.g. "") in it...
msg169671 - (view) Author: Chris Rebert (cvrebert) * Date: 2012-09-01 22:20
Attached updated patches.
msg170510 - (view) Author: Chris Rebert (cvrebert) * Date: 2012-09-15 06:09
Any reactions? The patch is pretty straightforward...
msg170522 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2012-09-15 16:35
I would recommend making the added and modified lines not exceed 79 characters in both files.  Also, for the .rst file, you can use slashes to break lines as shown in the following example:
msg170523 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2012-09-15 16:37
Also, while not strictly necessary, it is more customary and convenient to provide a single patch file for all files.
msg174010 - (view) Author: Chris Rebert (cvrebert) * Date: 2012-10-28 08:15
Per Chris Jerdonek, here's a combined patch that also makes the docs changes comply with the antiquated line length limit.
msg174034 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-10-28 12:13
New changeset 40aedc7da30f by Andrew Svetlov in branch '3.2':
Issue #14570: Document json sort_keys parameter properly.

New changeset 090484ccba7d by Andrew Svetlov in branch '3.3':
Merge issue #14570: Document json sort_keys parameter properly.

New changeset 27ce005372a5 by Andrew Svetlov in branch 'default':
Merge issue #14570: Document json sort_keys parameter properly.
msg174035 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2012-10-28 12:15
Thanks, Chris!
I have pushed the patch for 3.2-3.4
It cannot be applied to 2.7, please make separate patch for this version.
msg174041 - (view) Author: Chris Rebert (cvrebert) * Date: 2012-10-28 12:43
Patch for 2.7. This assumes that changing the parameter notation is permissible.
msg174045 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-10-28 12:59
New changeset 7784008e9ade by Andrew Svetlov in branch '2.7':
Issue #14570: Document json sort_keys parameter properly.
msg174046 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2012-10-28 12:59
Fixed, thanks again!
Date User Action Args
2012-10-28 12:59:51asvetlovsetstatus: open -> closed
resolution: fixed
messages: + msg174046

stage: patch review -> resolved
2012-10-28 12:59:00python-devsetmessages: + msg174045
2012-10-28 12:43:23cvrebertsetfiles: + issue14570-2.7.diff

messages: + msg174041
2012-10-28 12:15:09asvetlovsetnosy: + asvetlov
messages: + msg174035
2012-10-28 12:13:24python-devsetnosy: + python-dev
messages: + msg174034
2012-10-28 08:15:53cvrebertsetfiles: + issue14570.diff

messages: + msg174010
2012-09-15 16:37:35chris.jerdoneksetmessages: + msg170523
2012-09-15 16:35:10chris.jerdoneksetnosy: + chris.jerdonek
messages: + msg170522
2012-09-15 06:12:54ezio.melottisetnosy: + petri.lehtinen

stage: needs patch -> patch review
2012-09-15 06:09:04cvrebertsetmessages: + msg170510
2012-09-01 22:20:18cvrebertsetfiles: + json_init.patch

messages: + msg169671
2012-09-01 22:13:31cvrebertsetfiles: + json.rst.patch
2012-08-27 07:46:29cvrebertsetnosy: + cvrebert
messages: + msg169189
2012-04-30 18:17:45godfrydsetfiles: + json-sort-keys.patch
keywords: + patch
messages: + msg159719
2012-04-28 20:38:46godfrydsetnosy: + godfryd
messages: + msg159539
2012-04-13 06:38:27ezio.melottisetnosy: + ezio.melotti
2012-04-13 02:42:27ncoghlancreate