core.jsonio

Generic JSON I/O utilities.

Exceptions

JsonDecodeError

Exception raised when JSON decoding fails.

JsonIOError

Base exception for JSON I/O operations.

Functions

load(→ dict)

Load JSON data from a file.

save(path, data, *[, indent, sort_keys, ensure_ascii])

Save dictionary data to a JSON file.

Module Contents

exception JsonDecodeError

Bases: JsonIOError

Exception raised when JSON decoding fails.

exception JsonIOError

Bases: Exception

Base 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.