Skip to content

Commit 9ec9ac3

Browse files
committed
Add example use case for object_pairs_hook
1 parent 9405767 commit 9ec9ac3

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

Doc/library/json.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ Basic Usage
230230
*object_pairs_hook* is an optional function that will be called with the
231231
result of any object literal decoded with an ordered list of pairs. The
232232
return value of *object_pairs_hook* will be used instead of the
233-
:class:`dict`. This feature can be used to implement custom decoders that
234-
rely on the order that the key and value pairs are decoded. If *object_hook*
233+
:class:`dict`. This feature can be used to implement custom decoders (for
234+
example, sort keys before creating dict). If *object_hook*
235235
is also defined, the *object_pairs_hook* takes priority.
236236

237237
.. versionchanged:: 3.1
@@ -324,9 +324,9 @@ Encoders and Decoders
324324
*object_pairs_hook*, if specified will be called with the result of every
325325
JSON object decoded with an ordered list of pairs. The return value of
326326
*object_pairs_hook* will be used instead of the :class:`dict`. This
327-
feature can be used to implement custom decoders that rely on the order
328-
that the key and value pairs are decoded. If *object_hook* is also defined,
329-
the *object_pairs_hook* takes priority.
327+
feature can be used to implement custom decoders (for example, sort keys
328+
before creating dict). If *object_hook* is also defined, the
329+
*object_pairs_hook* takes priority.
330330

331331
.. versionchanged:: 3.1
332332
Added support for *object_pairs_hook*.

Lib/json/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,9 @@ def load(fp, *, cls=None, object_hook=None, parse_float=None,
284284
``object_pairs_hook`` is an optional function that will be called with the
285285
result of any object literal decoded with an ordered list of pairs. The
286286
return value of ``object_pairs_hook`` will be used instead of the ``dict``.
287-
This feature can be used to implement custom decoders that rely on the
288-
order that the key and value pairs are decoded. If ``object_hook`` is also
289-
defined, the ``object_pairs_hook`` takes priority.
287+
This feature can be used to implement custom decoders (e.g. sort by keys
288+
before creating dict). If ``object_hook`` is also defined, the
289+
``object_pairs_hook`` takes priority.
290290
291291
To use a custom ``JSONDecoder`` subclass, specify it with the ``cls``
292292
kwarg; otherwise ``JSONDecoder`` is used.
@@ -311,9 +311,9 @@ def loads(s, *, encoding=None, cls=None, object_hook=None, parse_float=None,
311311
``object_pairs_hook`` is an optional function that will be called with the
312312
result of any object literal decoded with an ordered list of pairs. The
313313
return value of ``object_pairs_hook`` will be used instead of the ``dict``.
314-
This feature can be used to implement custom decoders that rely on the
315-
order that the key and value pairs are decoded. If ``object_hook`` is also
316-
defined, the ``object_pairs_hook`` takes priority.
314+
This feature can be used to implement custom decoders (e.g. sort by keys
315+
before creating dict). If ``object_hook`` is also defined, the
316+
``object_pairs_hook`` takes priority.
317317
318318
``parse_float``, if specified, will be called with the string
319319
of every JSON float to be decoded. By default this is equivalent to

Lib/json/decoder.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,9 @@ def __init__(self, *, object_hook=None, parse_float=None,
292292
``object_pairs_hook``, if specified will be called with the result of
293293
every JSON object decoded with an ordered list of pairs. The return
294294
value of ``object_pairs_hook`` will be used instead of the ``dict``.
295-
This feature can be used to implement custom decoders that rely on the
296-
order that the key and value pairs are decoded. If ``object_hook``
297-
is also defined, the ``object_pairs_hook`` takes priority.
295+
This feature can be used to implement custom decoders (e.g. sort by
296+
keys before creating dict). If ``object_hook`` is also defined, the
297+
``object_pairs_hook`` takes priority.
298298
299299
``parse_float``, if specified, will be called with the string
300300
of every JSON float to be decoded. By default this is equivalent to

0 commit comments

Comments
 (0)