[英]Extract an element value in json using jsonpath
以下是我的 json 數據
{
"primary": [
{
"secondary": {
"name": {
"fullname": "fullname1"
},
"alias": "alias1"
},
"reference": "reference1"
},
{
"secondary": {
"name": {
"fullname": "fullname2"
},
"alias": "alias2"
},
"reference": "reference2"
}
]
}
現在我想使用 jsonpath 從這個 json 數據中提取基於條件的全名值的“別名”值。
我正在使用以下表達式但未能解析結果
$.primary[*].secondary[?(@.name.fullname == "fullname1")].alias
您的 JSON 格式不正確,如果它真的看起來像您發布的那樣 - 您將無法使用 JSON 提取器,您將不得不切換到正則表達式提取器。
有效的 JSON 將類似於:
{
"primary": [
{
"secondary": {
"name": {
"fullname": "fullname1"
},
"alias": "alias1"
},
"reference": "reference1"
},
{
"secondary": {
"name": {
"fullname": "fullname2"
},
"alias": "alias2"
},
"reference": "reference2"
},
{
"type": "online"
}
]
}
如果正確,您的JsonPath表達式可以正常工作, 因為 View Results Tree 偵聽器的 JsonPath Tester 模式證明了這一點:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.