Skip to content

declearn.utils.json_load

Load data from a JSON file, using extended types support.

This function is merely a shortcut to run the following code:

>>> with open(path, "r", encoding=encoding) as file:
>>>     return json.load(file, object_hook=declearn.utils.json_unpack)

See declearn.utils.add_json_support to extend the behaviour of JSON (de)serialization to non-standard types, that will be used as part of this function.

See declearn.utils.json_dump for the counterpart method.

Source code in declearn/utils/_json.py
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
def json_load(
    path: str,
    encoding: str = "utf-8",
) -> Any:
    """Load data from a JSON file, using extended types support.

    This function is merely a shortcut to run the following code:
    ```
    >>> with open(path, "r", encoding=encoding) as file:
    >>>     return json.load(file, object_hook=declearn.utils.json_unpack)
    ```

    See `declearn.utils.add_json_support` to extend the behaviour
    of JSON (de)serialization to non-standard types, that will be
    used as part of this function.

    See `declearn.utils.json_dump` for the counterpart method.
    """
    with open(path, "r", encoding=encoding) as file:
        return json.load(file, object_hook=json_unpack)