JsonPath - 通过过滤另一个节点的存在来选择节点

时间:2017-08-16 07:53:20

标签: json jsonpath

我是JSON路径的新手,似乎无法想象如何解决我的问题。我希望输出与'component1'对应的所有URL。对于验证,我使用了:http://jsonpath.com

这是我的JSON文件:

{
    "Portfolio":{
        "Website 1":{
            "url":"https://www.website1.com",
            "components":[
                "component1",
                "component2",
                "component3"
            ]
        },
        "Website 2":{
            "url":"https://www.website2.com",
            "components":[
                "component5",
                "component1",
                "component4"
            ]
        }
    }
}

1 个答案:

答案 0 :(得分:0)

你可以用:

$.Portfolio[?(@.components.indexOf('component1') !== -1)].url

提到here?()允许您将JavaScript代码作为过滤器运行。

我鼓励您准确了解这是在做什么,并在下次发布时自己尝试解决问题。

相关问题