jsonyx.read

jsonyx.read(filename, *, allow=NOTHING, cache_keys=False, hooks=None)[source]

Deserialize a 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:
  • filename (_StrPath) – the path to the 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

Raises:
Returns:

Any – a Python object.

Example:
>>> import jsonyx as json
>>> from pathlib import Path
>>> from tempfile import TemporaryDirectory
>>> with TemporaryDirectory() as tmpdir:
...     filename = Path(tmpdir) / "file.json"
...     _ = filename.write_text('["filesystem API"]', "utf-8")
...     json.read(filename)
...
['filesystem API']