Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update documentation for array_hook parameter
  • Loading branch information
jsbueno committed Mar 26, 2026
commit cdb6dcfa8f38009d0061f53613ee42636da013a7
24 changes: 22 additions & 2 deletions Doc/library/json.rst
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ Basic Usage

.. function:: load(fp, *, cls=None, object_hook=None, parse_float=None, \
parse_int=None, parse_constant=None, \
object_pairs_hook=None, **kw)
object_pairs_hook=None, array_hook=None, **kw)

Deserialize *fp* to a Python object
using the :ref:`JSON-to-Python conversion table <json-to-py-table>`.
Expand Down Expand Up @@ -301,6 +301,15 @@ Basic Usage
Default ``None``.
:type object_pairs_hook: :term:`callable` | None

:param array_hook:
If set, a function that is called with the result of
any JSON array literal decoded with 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.
Default ``None``.
:type array_hook: :term:`callable` | None

:param parse_float:
If set, a function that is called with
the string of every JSON float to be decoded.
Expand Down Expand Up @@ -349,7 +358,10 @@ Basic Usage
conversion length limitation <int_max_str_digits>` to help avoid denial
of service attacks.

.. function:: loads(s, *, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw)
.. versionchanged:: 3.15
Comment thread
jsbueno marked this conversation as resolved.
Outdated
* Added the optional *array_hook* parameter.
Comment thread
jsbueno marked this conversation as resolved.
Outdated

.. function:: loads(s, *, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, array_hook=None, **kw)

Identical to :func:`load`, but instead of a file-like object,
deserialize *s* (a :class:`str`, :class:`bytes` or :class:`bytearray`
Expand Down Expand Up @@ -412,6 +424,14 @@ Encoders and Decoders
.. versionchanged:: 3.1
Added support for *object_pairs_hook*.

*array_hook* is an optional function that will be called with the
Comment thread
jsbueno marked this conversation as resolved.
result of every JSON array decoded as a list. The return value of
*array_hook* will be used instead of the :class:`list`. This feature can be
used to implement custom decoders.

.. versionchanged:: 3.15
Comment thread
jsbueno marked this conversation as resolved.
Outdated
Added support for *array_hook*.

*parse_float* is an optional function that will be called with the string of
every JSON float to be decoded. By default, this is equivalent to
``float(num_str)``. This can be used to use another datatype or parser for
Expand Down
Loading