如何找到 jsonpath 兄弟

how to find jsonpath sibling

我需要一些关于使用 jsonpath 查找兄弟姐妹的帮助。我想找到所有价格为 0 美元的地点。尝试了 $..price[?(@.lowest <= 0)] 等几个选项,但它只选择匹配的节点。

感谢您的协助

[{
"fromDate": "2018-03-30",
"images": [{
    "type": "LARGE",
    "url": ""
}],
"price": {
    "currencySymbol": "$",
    "lowest": 0
},
"toDate": "2018-04-07",
"location": "Newyork, NY",
"priceSuffix": "per night",
"details": "2-Bedrooms" 
},
{
"fromDate": "2018-03-30",
"images": [{
    "type": "LARGE",
    "url": ""
}],
"price": {
    "currencySymbol": "$",
    "lowest": 0
},
"toDate": "2018-04-07",
"location": "Atlanta, GA",
"priceSuffix": "per night",
"details": "2-Bedrooms" 
}]

这是一个基于您的数据的工作示例,您可以剪切和粘贴并自己尝试:

* def json = 
"""
[{
"fromDate": "2018-03-30",
"images": [{
    "type": "LARGE",
    "url": ""
}],
"price": {
    "currencySymbol": "$",
    "lowest": 0
},
"toDate": "2018-04-07",
"location": "Newyork, NY",
"priceSuffix": "per night",
"details": "2-Bedrooms" 
},
{
"fromDate": "2018-03-30",
"images": [{
    "type": "LARGE",
    "url": ""
}],
"price": {
    "currencySymbol": "$",
    "lowest": 1
},
"toDate": "2018-04-07",
"location": "Atlanta, GA",
"priceSuffix": "per night",
"details": "2-Bedrooms" 
}]
"""
* def zero = $json[?(@.price.lowest==0)]
* match zero[0].location == 'Newyork, NY'
* def one = $json[?(@.price.lowest==1)]
* match one[0].location == 'Atlanta, GA'