python 查找json下值包含某某的绝对路径

import jsonpath


def get_json_path(value, json):
    """
    查找json下值包含value的绝对路径
    :param value: 查找的值
    :param json: 被查找的json
    :return: list[value,path]
    """
    try:
        path = [[value, path] for value, path in zip(
            jsonpath.jsonpath(json, f'$..*[?("{value}" in @]).'),
            jsonpath.jsonpath(json, f'$..*[?("{value}" in @]).', result_type="PATH"))]
        return path
    except Exception as e:
        print('错误内容%s' % e)

你可能感兴趣的:(python)