core.jsonio¶
Generic JSON I/O utilities.
Exceptions¶
Exception raised when JSON decoding fails. |
|
Base exception for JSON I/O operations. |
Functions¶
Module Contents¶
- exception JsonDecodeError¶
Bases:
JsonIOErrorException raised when JSON decoding fails.
- exception JsonIOError¶
Bases:
ExceptionBase exception for JSON I/O operations.
- load(path: pathlib.Path | str) dict¶
Load JSON data from a file.
- Args:
path: Path to the JSON file.
- Returns:
Parsed JSON data as a dictionary.
- Raises:
FileNotFoundError: If the file does not exist. JsonDecodeError: If the file contains invalid JSON.
- save(path: pathlib.Path | str, data: dict, *, indent: int = 2, sort_keys: bool = True, ensure_ascii: bool = False)¶
Save dictionary data to a JSON file.
- Args:
path: Path where the JSON file will be saved. data: Dictionary data to save. indent: Number of spaces for indentation (default: 2). sort_keys: Whether to sort dictionary keys (default: True). ensure_ascii: Whether to escape non-ASCII characters (default: False).
- Note:
Parent directories will be created automatically if they don’t exist.