Skip to content

Commit 3b3efc6

Browse files
committed
gh-146440: Add an example for the json array_hook decoder parameter
1 parent eb44708 commit 3b3efc6

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

Doc/library/json.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ Customizing JSON object decoding::
9999
>>> import decimal
100100
>>> json.loads('1.1', parse_float=decimal.Decimal)
101101
Decimal('1.1')
102+
>>> json.loads('{"name": "point", "coords": [[1, 2], [3, 4]]}',
103+
... array_hook=tuple) # doctest: +SKIP
104+
{'name': 'point', 'coords': ((1, 2), (3, 4))}
105+
>>> json.loads('{"name": "point", "coords": [1, 2]}',
106+
... object_pairs_hook=frozendict, array_hook=tuple) # doctest: +SKIP
107+
frozendict({'name': 'point', 'coords': (1, 2)})
102108

103109
Extending :class:`JSONEncoder`::
104110

@@ -303,7 +309,7 @@ Basic Usage
303309

304310
:param array_hook:
305311
If set, a function that is called with the result of
306-
any JSON array literal decoded with as a Python list.
312+
any JSON array literal decoded as a Python list.
307313
The return value of this function will be used
308314
instead of the :class:`list`.
309315
This feature can be used to implement custom decoders.

Lib/json/decoder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ def __init__(self, *, object_hook=None, parse_float=None,
314314
be used along ``object_pairs_hook`` to customize the resulting data
315315
structure - for example, by setting that to ``frozendict`` and
316316
``array_hook`` to ``tuple``, one can get a deep immutable data
317-
structute from any JSON data.
317+
structure from any JSON data.
318318
319319
``parse_float``, if specified, will be called with the string
320320
of every JSON float to be decoded. By default this is equivalent to

0 commit comments

Comments
 (0)