Skip to content

Read json

read_json_file(path_to_file)

Read a json file from a given path.

Parameters:

Name Type Description Default
path_to_file str

path to json file

required

Returns:

Type Description
dict

A dict with json data

Source code in johnson/read_json.py
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
def read_json_file(path_to_file: str) -> dict:
    """
    Read a json file from a given path.

    Parameters:
        path_to_file: path to json file

    Returns:
        A dict with json data
    """

    with open(path_to_file, 'r') as file:
        try:
            data = json.load(file)
            return data
        except json.decoder.JSONDecodeError as e:
            raise e