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_decimalwithhooks.Changed in version 2.2: Added
cache_keys(defaultFalseinstead ofTrue).- Parameters:
- Raises:
OSError – if the file can’t be opened
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 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.Decoderdirectly for better performance.See also
jsonyx.load()for deserializing from an open file.jsonyx.loads()for deserializing from a string.jsonyx.write()for serializing to a file.