summaryrefslogtreecommitdiff
path: root/index.rst
diff options
context:
space:
mode:
authorBob Ippolito <bob@redivi.com>2009-03-29 21:38:28 +0000
committerBob Ippolito <bob@redivi.com>2009-03-29 21:38:28 +0000
commit2e0050046dc4c35508758669ec02b5f8c8b091cf (patch)
tree01e8e8d8c1d63b211c106d7a7e02c717d0eb191d /index.rst
parent0d9f46d682a4af5fff44c1d3b01fe2ff00599ec3 (diff)
downloadsimplejson-2e0050046dc4c35508758669ec02b5f8c8b091cf.tar.gz
http://bugs.python.org/issue5381 ordered_pairs_hook backport to simplejson
git-svn-id: http://simplejson.googlecode.com/svn/trunk@178 a4795897-2c25-0410-b006-0d3caba88fa1
Diffstat (limited to 'index.rst')
-rw-r--r--index.rst28
1 files changed, 25 insertions, 3 deletions
diff --git a/index.rst b/index.rst
index 0bc8577..bfa3b8d 100644
--- a/index.rst
+++ b/index.rst
@@ -182,7 +182,7 @@ Basic Usage
better performance.
-.. 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.
@@ -199,6 +199,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:: 2.1.0
+ 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
@@ -226,7 +237,7 @@ Basic Usage
only one JSON document, it is recommended to use :func:`loads`.
-.. 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.
@@ -242,7 +253,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[, object_pairs_hook[, strict]]]]]]])
Simple JSON decoder.
@@ -283,6 +294,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* 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:: 2.1.0
+ 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