diff --git a/Doc/library/json.rst b/Doc/library/json.rst index 383ccad9df041b5..073da4b64b0cafa 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`:: @@ -303,7 +309,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 364e44d40cc3073..2afd6ced84361ea 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