Skip to content

json_file_operations

Functions for storing dicts to and loading dicts from json files.

load_json

load_json(path)

Load the info in the json file given by path and return as dict

Source code in src/application_settings/_private/json_file_operations.py
 8
 9
10
11
12
13
def load_json(path: Path) -> dict[str, Any]:
    """Load the info in the json file given by path and return as dict"""
    data_stored: dict[str, Any] = {}
    with path.open(mode="r") as fptr:
        data_stored = json.load(fptr)
    return data_stored

save_json

save_json(path, data)

Save the info in the data dict to the json file given by path

Source code in src/application_settings/_private/json_file_operations.py
16
17
18
19
def save_json(path: Path, data: dict[str, Any]) -> None:
    """Save the info in the data dict to the json file given by path"""
    with path.open(mode="w") as fptr:
        json.dump(data, fptr)