[英]Extract an element value in json using jsonpath
Following is my json data以下是我的 json 数据
{
"primary": [
{
"secondary": {
"name": {
"fullname": "fullname1"
},
"alias": "alias1"
},
"reference": "reference1"
},
{
"secondary": {
"name": {
"fullname": "fullname2"
},
"alias": "alias2"
},
"reference": "reference2"
}
]
}
Now I want to extract "alias" value based on condition based fullname value from this json data using jsonpath.现在我想使用 jsonpath 从这个 json 数据中提取基于条件的全名值的“别名”值。
I am using following expression but failed to parse result我正在使用以下表达式但未能解析结果
$.primary[*].secondary[?(@.name.fullname == "fullname1")].alias
$.primary[*].secondary[?(@.name.fullname == "fullname1")].alias
Your JSON is malformed, if it really looks like you posted - you won't be able to use JSON Extractor, you will have to switch to Regular Expression Extractor .您的 JSON 格式不正确,如果它真的看起来像您发布的那样 - 您将无法使用 JSON 提取器,您将不得不切换到正则表达式提取器。
Valid JSON would be something like:有效的 JSON 将类似于:
{
"primary": [
{
"secondary": {
"name": {
"fullname": "fullname1"
},
"alias": "alias1"
},
"reference": "reference1"
},
{
"secondary": {
"name": {
"fullname": "fullname2"
},
"alias": "alias2"
},
"reference": "reference2"
},
{
"type": "online"
}
]
}
And if it is correct your JsonPath expression works fine as it evidenced by JsonPath Tester mode of the View Results Tree listener :如果正确,您的JsonPath表达式可以正常工作, 因为 View Results Tree 侦听器的 JsonPath Tester 模式证明了这一点:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.