import ast


def getLastSavedWellName(path2json):
    """
    Iterates over the lines of the json file - each line is the data of another well, and returns the name of last well
    that was saved.

    Parameters
    ----------
    path2json: str
        Path to json file that is used to save the experiment's data

    Returns
    -------
    last_well_name: str
        The name of the last well that was saved (well name of the form: "B - 02")
    """
    # extract the last line of the json file which is the data of the last well as a dictionary
    with open(path2json, "r") as file:
        lastline = (list(file)[-1])
    last_dict = ast.literal_eval(lastline)
    # extract the name from the dictionary
    last_well_name = list(last_dict.keys())[0]
    return last_well_name