以下是我的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 Extractor,您必须切换到 Regular Expression Extractor 。
有效的 JSON 类似于:
{
"primary": [
{
"secondary": {
"name": {
"fullname": "fullname1"
},
"alias": "alias1"
},
"reference": "reference1"
},
{
"secondary": {
"name": {
"fullname": "fullname2"
},
"alias": "alias2"
},
"reference": "reference2"
},
{
"type": "online"
}
]
}
如果它是正确的,你的JsonPath表达式工作正常,如 JsonPath Tester mode of the View Results Tree listener 所证明的那样:
关于javascript - 使用 jsonpath 提取 json 中的元素值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58707788/