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_decimalwithhooks.Changed in version 2.2: Added
cache_keys(defaultFalseinstead ofTrue).- Parameters:
allow (
Container[str], default:NOTHING) – the JSON deviations fromjsonyx.allowcache_keys (
bool, default:False) – re-use the keys of objectshooks (
dict[str, _Hook] |None, default:None) – the hooks used for transforming dataroot (_StrPath, default:
".") – the path to the archive containing this JSON file
- Raises:
RecursionError – if the JSON file is too deeply nested
TruncatedSyntaxError – when failing to decode the file
ValueError – if a number is too big
- Returns:
Any– a Python object
- Example:
>>> import jsonyx as json >>> from io import StringIO >>> io = StringIO('["reader protocol"]') >>> json.load(io) ['reader protocol']
Tip
Specify
rootto display the zip filename in error messages.Use
jsonyx.Decoderdirectly for better performance.
Note
The input is not read incrementally, but in one-shot.
The encoding is detected using
jsonyx.detect_encoding().
See also
jsonyx.read()for deserializing from a file.jsonyx.loads()for deserializing from a string.jsonyx.dump()for serializing to an open file.