New submission from Eric O. LEBIGOT:

The JSON encoder for dictionaries preserves the order of the items in a 
dictionary: it would be useful to document this behavior, so that users can 
rely on it.

While JSON itself does not have ordered key/value pairs, this feature can be 
useful (for modifying the original JSON document while maintaining as much of 
it untouched, for manipulating our own extension of JSON with ordered 
dictionaries, etc.).

The documentation could also usefully mention that _reading_ sets of key/value 
pairs can also be done in an order-preserving way with 
`object_pairs_hook=OrderedDict`.

Reference: the json module does not alter the order of the dictionary items 
upon encoding: 
https://github.com/python/cpython/blob/aacd53f6cb96fe8c4fe9ce894f22e25f356a97c3/Lib/json/encoder.py#L355.

----------
components: Library (Lib)
messages: 295001
nosy: lebigot
priority: normal
severity: normal
status: open
title: Document order-preserving dictionary output
type: enhancement
versions: Python 3.6

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue30550>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to