JsonPath - 通过过滤另一个节点的存在来选择一个节点
JsonPath - selecting a node by filtering on the presence of another node
我是 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"
]
}
}
}
您可以使用:
$.Portfolio[?(@.components.indexOf('component1') !== -1)].url
提到here,?()
允许您运行JavaScript代码作为过滤器。
我鼓励您确切地了解它在做什么,并在您下次 post 来这里时自己尝试解决这个问题。
我是 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"
]
}
}
}
您可以使用:
$.Portfolio[?(@.components.indexOf('component1') !== -1)].url
提到here,?()
允许您运行JavaScript代码作为过滤器。
我鼓励您确切地了解它在做什么,并在您下次 post 来这里时自己尝试解决这个问题。