summaryrefslogtreecommitdiffstats
path: root/Doc/library/json.rst
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2009-04-21 03:27:12 (GMT)
committerRaymond Hettinger <python@rcn.com>2009-04-21 03:27:12 (GMT)
commit9b8d069b319feb18b8ae91e26533af46a69be997 (patch)
tree059f5f18162a05e9f1c27ffb533e11ef3e1b3ca8 /Doc/library/json.rst
parent0ad98d8509764ee3947c481103e1e735cc048305 (diff)
downloadcpython-9b8d069b319feb18b8ae91e26533af46a69be997.zip
cpython-9b8d069b319feb18b8ae91e26533af46a69be997.tar.gz
cpython-9b8d069b319feb18b8ae91e26533af46a69be997.tar.bz2
Forward port r70471: Add object_pairs_hook. Issue 5381.
Diffstat (limited to 'Doc/library/json.rst')
-rw-r--r--Doc/library/json.rst28
1 files changed, 25 insertions, 3 deletions
diff --git a/Doc/library/json.rst b/Doc/library/json.rst
index bd31a31..edaf657 100644
--- a/Doc/library/json.rst
+++ b/Doc/library/json.rst
@@ -165,7 +165,7 @@ Basic Usage
:func:`dump`.
-.. function:: load(fp[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, **kw]]]]]]])
+.. function:: load(fp[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, object_pairs_hook[, **kw]]]]]]]])
Deserialize *fp* (a ``.read()``-supporting file-like object containing a JSON
document) to a Python object.
@@ -181,6 +181,17 @@ Basic Usage
*object_hook* will be used instead of the :class:`dict`. This feature can be used
to implement custom decoders (e.g. JSON-RPC class hinting).
+ *object_pairs_hook* is an optional function that will be called with the
+ result of any object literal decode with an ordered list of pairs. The
+ return value of *object_pairs_hook* will be used instead of the
+ :class:`dict`. This feature can be used to implement custom decoders that
+ rely on the order that the key and value pairs are decoded (for example,
+ :func:`collections.OrderedDict` will remember the order of insertion). If
+ *object_hook* is also defined, the *object_pairs_hook* takes priority.
+
+ .. versionchanged:: 3.1
+ Added support for *object_pairs_hook*.
+
*parse_float*, if specified, will be called with the string of every JSON
float to be decoded. By default, this is equivalent to ``float(num_str)``.
This can be used to use another datatype or parser for JSON floats
@@ -201,7 +212,7 @@ Basic Usage
class.
-.. function:: loads(s[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, **kw]]]]]]])
+.. function:: loads(s[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, object_pairs_hook[, **kw]]]]]]]])
Deserialize *s* (a :class:`str` or :class:`unicode` instance containing a JSON
document) to a Python object.
@@ -217,7 +228,7 @@ Basic Usage
Encoders and decoders
---------------------
-.. class:: JSONDecoder([encoding[, object_hook[, parse_float[, parse_int[, parse_constant[, strict]]]]]])
+.. class:: JSONDecoder([encoding[, object_hook[, parse_float[, parse_int[, parse_constant[, strict[, object_pairs_hook]]]]]]])
Simple JSON decoder.
@@ -258,6 +269,17 @@ Encoders and decoders
:class:`dict`. This can be used to provide custom deserializations (e.g. to
support JSON-RPC class hinting).
+ *object_pairs_hook*, if specified will be called with the result of every
+ JSON object decoded with an ordered list of pairs. The return value of
+ *object_pairs_hook* will be used instead of the :class:`dict`. This
+ feature can be used to implement custom decoders that rely on the order
+ that the key and value pairs are decoded (for example,
+ :func:`collections.OrderedDict` will remember the order of insertion). If
+ *object_hook* is also defined, the *object_pairs_hook* takes priority.
+
+ .. versionchanged:: 3.1
+ Added support for *object_pairs_hook*.
+
*parse_float*, if specified, will be called with the string of every JSON
float to be decoded. By default, this is equivalent to ``float(num_str)``.
This can be used to use another datatype or parser for JSON floats