https://github.com/python/cpython/commit/6d6b1ab4c8a8f3d1c94b3fa94e691cf9a81d2589
commit: 6d6b1ab4c8a8f3d1c94b3fa94e691cf9a81d2589
branch: main
author: Vyron Vasileiadis <[email protected]>
committer: ambv <[email protected]>
date: 2026-10-23T12:07:03-07:00
summary:

gh-146440: Add an example for the json array_hook decoder parameter (GH-154522)

files:
M Doc/library/json.rst
M Lib/json/decoder.py

diff --git a/Doc/library/json.rst b/Doc/library/json.rst
index 0d115c5623fd7de..8e6340b647c3acf 100644
--- a/Doc/library/json.rst
+++ b/Doc/library/json.rst
@@ -99,6 +99,12 @@ Customizing JSON object decoding::
     >>> import decimal
     >>> json.loads('1.1', parse_float=decimal.Decimal)
     Decimal('1.1')
+    >>> json.loads('{"name": "point", "coords": [[1, 2], [3, 4]]}',
+    ...     array_hook=tuple)  # doctest: +SKIP
+    {'name': 'point', 'coords': ((1, 2), (3, 4))}
+    >>> json.loads('{"name": "point", "coords": [1, 2]}',
+    ...     object_pairs_hook=frozendict, array_hook=tuple)  # doctest: +SKIP
+    frozendict({'name': 'point', 'coords': (1, 2)})
 
 Extending :class:`JSONEncoder`::
 
@@ -304,7 +310,7 @@ Basic Usage
 
    :param array_hook:
       If set, a function that is called with the result of
-      any JSON array literal decoded with as a Python list.
+      any JSON array literal decoded as a Python list.
       The return value of this function will be used
       instead of the :class:`list`.
       This feature can be used to implement custom decoders.
diff --git a/Lib/json/decoder.py b/Lib/json/decoder.py
index 3150a29405f75c3..ee0464318458117 100644
--- a/Lib/json/decoder.py
+++ b/Lib/json/decoder.py
@@ -314,7 +314,7 @@ def __init__(self, *, object_hook=None, parse_float=None,
         be used along ``object_pairs_hook`` to customize the resulting data
         structure - for example, by setting that to ``frozendict`` and
         ``array_hook`` to ``tuple``, one can get a deep immutable data
-        structute from any JSON data.
+        structure from any JSON data.
 
         ``parse_float``, if specified, will be called with the string
         of every JSON float to be decoded. By default this is equivalent to

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to