首页 > 解决方案 > 有没有办法找到密钥是否存在 jsonpath-ng

问题描述

例如 :

client_json = {
    "data": [
        {
            "attributes": {
                "creators": [
                    {
                        "name": "This is a person",
                        "nameType": "Personal",
                        "givenName": "the",
                        "familyName": "person"
                    },
                    {
                        "name": "This is an organization",
                        "nameType": "Organizational",
                        "givenName": "the",
                        "familyName": "organization"
                    }
                ]
            }
        }
    ]
}

在上面的 json 中,我想检查这个 json 路径是否存在键,$.[0].attributes.creators[0].name,我不担心值。

我可以这样做jsonpath-ng吗?我以前使用jsonpath过 Stefan Goessner 的图书馆,但现在已经过时了。

我想要python中与类似但确实存在()的东西

标签: pythonjsonpathjsonpath-ng

解决方案


据我所知,您不必使用任何类型的库来进行查找。由于 Python 像字典一样处理 JSON。这是我会尝试的:

for key in client_json.items():
    print key

推荐阅读