Issue 14570: Document json "sort_keys" parameter properly (original) (raw)

Created on 2012-04-13 02:42 by ncoghlan, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (14)

msg158194 - (view)

Author: Alyssa 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, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, cls=None, indent=None, separators=None, default=None, **kw)

json.JSONEncoder(skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)

Some of dump/dumps arguments are passed to encoder class:

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:

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:

http://hg.python.org/cpython/file/09011896374d/Doc/library/argparse.rst#l133

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. http://hg.python.org/cpython/rev/40aedc7da30f

New changeset 090484ccba7d by Andrew Svetlov in branch '3.3': Merge issue #14570: Document json sort_keys parameter properly. http://hg.python.org/cpython/rev/090484ccba7d

New changeset 27ce005372a5 by Andrew Svetlov in branch 'default': Merge issue #14570: Document json sort_keys parameter properly. http://hg.python.org/cpython/rev/27ce005372a5

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. http://hg.python.org/cpython/rev/7784008e9ade

msg174046 - (view)

Author: Andrew Svetlov (asvetlov) * (Python committer)

Date: 2012-10-28 12:59

Fixed, thanks again!

History

Date

User

Action

Args

2022-04-11 14:57:29

admin

set

github: 58775

2012-10-28 12:59:51

asvetlov

set

status: open -> closed
resolution: fixed
messages: +

stage: patch review -> resolved

2012-10-28 12:59:00

python-dev

set

messages: +

2012-10-28 12:43:23

cvrebert

set

files: + issue14570-2.7.diff

messages: +

2012-10-28 12:15:09

asvetlov

set

nosy: + asvetlov
messages: +

2012-10-28 12:13:24

python-dev

set

nosy: + python-dev
messages: +

2012-10-28 08:15:53

cvrebert

set

files: + issue14570.diff

messages: +

2012-09-15 16:37:35

chris.jerdonek

set

messages: +

2012-09-15 16:35:10

chris.jerdonek

set

nosy: + chris.jerdonek
messages: +

2012-09-15 06:12:54

ezio.melotti

set

nosy: + petri.lehtinen

stage: needs patch -> patch review

2012-09-15 06:09:04

cvrebert

set

messages: +

2012-09-01 22:20:18

cvrebert

set

files: + json_init.patch

messages: +

2012-09-01 22:13:31

cvrebert

set

files: + json.rst.patch

2012-08-27 07:46:29

cvrebert

set

nosy: + cvrebert
messages: +

2012-04-30 18:17:45

godfryd

set

files: + json-sort-keys.patch
keywords: + patch
messages: +

2012-04-28 20:38:46

godfryd

set

nosy: + godfryd
messages: +

2012-04-13 06:38:27

ezio.melotti

set

nosy: + ezio.melotti

2012-04-13 02:42:27

ncoghlan

create