[英]JSONPath - Filter expression is not working as expected
無法讓 JSONPath 工作。
JSON:
{
"data": [
{
"meta": {
"definition": {
"title": "ID",
"type": "text",
"key": "657876498"
}
},
"attributes": {
"id": "8606798",
"name": "ID",
"content": {
"value": "ABC"
}
}
}
]
}
小路:
$.data[*].attributes[?(@.name=='ID')]
在jsonpath.com或在 python 中使用jsonpath-ng
時返回不匹配。
我從根本上錯過了什么,這個過濾器不起作用?
注意:最終目標是獲取name
和content.value
。
編輯:
在https://jsonpath.herokuapp.com/路徑實際上有效。 嗯...實現依賴?
事實上,這似乎是 jsonpath-ng 實現的一個特質。 看起來“過濾器操作只能用於列表” ,即可迭代。
作為一種解決方法,我們可以過濾data
-array 並在之后提取attributes
:
$.data[?(@.attributes.name="ID")].attributes
這與使用您的路徑的 Jayway 的 JsonPath 給出相同的結果; 但是,這種方法可能並非在所有情況下都令人滿意。
請嘗試以下路徑獲取name
和content.value
值
$.data[:0].attributes.name
$.data[:0].attributes.content.value
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.