def wrap_with_links(obj, links, val, root_path, many=False):
    """Adds links key to object (first argument) based on links dictionary and value"""
    if many:
        for item in obj:
            item['links'] = {}
            for key in links:
                item['links'][key] = root_path + links[key].format(item[val])
    else:
        obj['links'] = {}
        for key in links:
            obj['links'][key] = root_path + links[key].format(obj[val])
    return obj