def flatten_json(data, delimiter):
    """
    Flattens a JSON file.
    Input:
        data:
            A JSON dictionary of hierarchical format.
            {key1: {key2: value2, key3: value3}, key4: {key5: value5, key6: [value6, value7, value8]}}
        delimiter:
            A parameter to separate the keys in order to facilitate easy splitting.
    Output:
        A flattened dictionary with keys separated by the delimiter parameter.
        key1_key2:value2, key1_key3:value3, key4_key5:value5, key4_key6:value6, key4_key6:value7, key4_key6:value8
    """

    out = {}

    def flatten(data, name=''):
        if type(data) is dict:
            for key in data:
                flatten(data[key], name + key + delimiter)
        elif type(data) is list:
            i = 0
            for elem in data:
                flatten(elem, name + str(i) + delimiter)
                i += 1
        else:
            out[name[:-1]] = data

    flatten(data)
    return out