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 (default False instead of True).

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 os.path import join
>>> from tempfile import TemporaryDirectory
>>> with TemporaryDirectory() as tmpdir:
...     filename = join(tmpdir, "file.json")
...     with open(filename, "w", encoding="utf-8") as fp:
...         _ = fp.write('["filesystem API"]')
...     json.load(filename)
...
['filesystem API']

Tip

Use jsonyx.Decoder directly for better performance.

See also