[issue14570] Document json "sort_keys" parameter properly

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[issue14570] Document json "sort_keys" parameter properly

STINNER Victor

New submission from Nick Coghlan <[hidden email]>:

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.

----------
assignee: docs@python
components: Documentation
keywords: easy
messages: 158194
nosy: docs@python, ncoghlan
priority: normal
severity: normal
stage: needs patch
status: open
title: Document json "sort_keys" parameter properly
type: enhancement
versions: Python 2.7, Python 3.2, Python 3.3

_______________________________________
Python tracker <[hidden email]>
<http://bugs.python.org/issue14570>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/lists%2B1322467933539-512619%40n6.nabble.com

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[issue14570] Document json "sort_keys" parameter properly

STINNER Victor

Changes by Ezio Melotti <[hidden email]>:


----------
nosy: +ezio.melotti

_______________________________________
Python tracker <[hidden email]>
<http://bugs.python.org/issue14570>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/lists%2B1322467933539-512619%40n6.nabble.com

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[issue14570] Document json "sort_keys" parameter properly

STINNER Victor
In reply to this post by STINNER Victor

Michal Nowikowski <[hidden email]> added the comment:

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:
- 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.

----------
nosy: +godfryd

_______________________________________
Python tracker <[hidden email]>
<http://bugs.python.org/issue14570>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/lists%2B1322467933539-512619%40n6.nabble.com

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[issue14570] Document json "sort_keys" parameter properly

STINNER Victor
In reply to this post by STINNER Victor

Michal Nowikowski <[hidden email]> added the comment:

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.

----------
keywords: +patch
Added file: http://bugs.python.org/file25427/json-sort-keys.patch

_______________________________________
Python tracker <[hidden email]>
<http://bugs.python.org/issue14570>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/lists%2B1322467933539-512619%40n6.nabble.com

Loading...