jsonyx.load

jsonyx.load(fp, *, allow=NOTHING, cache_keys=False, hooks=None, root='.')[source]

Deserialize an open JSON file to a Python object.

Changed in version 2.0: Replaced use_decimal with hooks.

Changed in version 2.2:

  • Added cache_keys.

  • Disabled caching keys by default.

Parameters:
  • fp (_SupportsRead[bytes | str]) – an open JSON file

  • allow (Container[str], default: NOTHING) – the JSON deviations from jsonyx.allow

  • cache_keys (bool, default: False) – re-use the keys of objects

  • hooks (dict[str, _Hook] | None, default: None) – the hooks used for transforming data

  • root (_StrPath, default: ".") – the path to the archive containing this JSON file

Raises:

TruncatedSyntaxError – when failing to decode the file

Returns:

Any – a Python object

Example:
>>> import jsonyx as json
>>> from io import StringIO
>>> io = StringIO('["streaming API"]')
>>> json.load(io)
['streaming API']

Tip

Specify root to display the zip filename in error messages.