import json


def get_filtered_keys_from_map(key_map, payload):
    """
    Filter the payload for the given keylist and return the filtered dict
    :param key_list: a json old_key:new_key map in string format
    :param payload: dict payload which needs to be filtered
    :return: dict with new_key, value pair based on the keylist
    """

    ret_dict = dict()
    key_map = json.loads(key_map)

    for old_key, new_key in key_map:
        value = payload.get(old_key)
        if not value:
            raise KeyError("Key: {} not present in payload: {} for key map: {}"
                           .format(old_key, payload, key_map))
        ret_dict[new_key] = value
    return ret_dict