@@ -166,7 +166,7 @@ Basic Usage
166166 :func: `dump `.
167167
168168
169- .. function :: load(fp[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, **kw]]]]]]])
169+ .. function :: load(fp[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, object_pairs_hook[, **kw] ]]]]]]])
170170
171171 Deserialize *fp * (a ``.read() ``-supporting file-like object containing a JSON
172172 document) to a Python object.
@@ -182,6 +182,17 @@ Basic Usage
182182 *object_hook * will be used instead of the :class: `dict `. This feature can be used
183183 to implement custom decoders (e.g. JSON-RPC class hinting).
184184
185+ *object_pairs_hook * is an optional function that will be called with the
186+ result of any object literal decode with an ordered list of pairs. The
187+ return value of *object_pairs_hook * will be used instead of the
188+ :class: `dict `. This feature can be used to implement custom decoders that
189+ rely on the order that the key and value pairs are decoded (for example,
190+ :func: `collections.OrderedDict ` will remember the order of insertion). If
191+ *object_hook * is also defined, the *object_pairs_hook * takes priority.
192+
193+ .. versionchanged :: 2.7
194+ Added support for *object_pairs_hook *.
195+
185196 *parse_float *, if specified, will be called with the string of every JSON
186197 float to be decoded. By default, this is equivalent to ``float(num_str) ``.
187198 This can be used to use another datatype or parser for JSON floats
@@ -202,7 +213,7 @@ Basic Usage
202213 class.
203214
204215
205- .. function :: loads(s[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, **kw]]]]]]])
216+ .. function :: loads(s[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, object_pairs_hook[, **kw] ]]]]]]])
206217
207218 Deserialize *s * (a :class: `str ` or :class: `unicode ` instance containing a JSON
208219 document) to a Python object.
@@ -218,7 +229,7 @@ Basic Usage
218229Encoders and decoders
219230---------------------
220231
221- .. class :: JSONDecoder([encoding[, object_hook[, parse_float[, parse_int[, parse_constant[, strict]]]]]])
232+ .. class :: JSONDecoder([encoding[, object_hook[, parse_float[, parse_int[, parse_constant[, strict[, object_pairs_hook] ]]]]]])
222233
223234 Simple JSON decoder.
224235
@@ -259,6 +270,17 @@ Encoders and decoders
259270 :class: `dict `. This can be used to provide custom deserializations (e.g. to
260271 support JSON-RPC class hinting).
261272
273+ *object_pairs_hook *, if specified will be called with the result of every
274+ JSON object decoded with an ordered list of pairs. The return value of
275+ *object_pairs_hook * will be used instead of the :class: `dict `. This
276+ feature can be used to implement custom decoders that rely on the order
277+ that the key and value pairs are decoded (for example,
278+ :func: `collections.OrderedDict ` will remember the order of insertion). If
279+ *object_hook * is also defined, the *object_pairs_hook * takes priority.
280+
281+ .. versionchanged :: 2.7
282+ Added support for *object_pairs_hook *.
283+
262284 *parse_float *, if specified, will be called with the string of every JSON
263285 float to be decoded. By default, this is equivalent to ``float(num_str) ``.
264286 This can be used to use another datatype or parser for JSON floats
0 commit comments