JsonPath 从其他数组中获取数组元素
JsonPath get array element from inside other array
我刚刚了解 JsonPath。我正在使用 jsonpath.com 并在其中粘贴下面的示例,尝试根据 Donna 的名字进行搜索。
类似于:
$.prizes[?(@.laureates.firstname == Donna)]
但这不起作用。是否可以使用 ?(@.)
类型的表达式来搜索名字 Donna 并使结果为:
[
{
"id": "962",
"firstname": "Donna",
"surname": "Strickland",
"motivation": "\"for their method of generating high-intensity, ultra-short optical pulses\"",
"share": "4"
}
]
原始数据如下:
{
"prizes": [
{
"year": "2018",
"category": "physics",
"overallMotivation": "\"for groundbreaking inventions in the field of laser physics\"",
"laureates": [
{
"id": "960",
"firstname": "Arthur",
"surname": "Ashkin",
"motivation": "\"for the optical tweezers and their application to biological systems\"",
"share": "2"
},
{
"id": "961",
"firstname": "Gérard",
"surname": "Mourou",
"motivation": "\"for their method of generating high-intensity, ultra-short optical pulses\"",
"share": "4"
},
{
"id": "962",
"firstname": "Donna",
"surname": "Strickland",
"motivation": "\"for their method of generating high-intensity, ultra-short optical pulses\"",
"share": "4"
}
]
}
]
}
你快到了;尝试:
$.prizes..laureates[?(@.firstname == "Donna")]
我刚刚了解 JsonPath。我正在使用 jsonpath.com 并在其中粘贴下面的示例,尝试根据 Donna 的名字进行搜索。
类似于:
$.prizes[?(@.laureates.firstname == Donna)]
但这不起作用。是否可以使用 ?(@.)
类型的表达式来搜索名字 Donna 并使结果为:
[
{
"id": "962",
"firstname": "Donna",
"surname": "Strickland",
"motivation": "\"for their method of generating high-intensity, ultra-short optical pulses\"",
"share": "4"
}
]
原始数据如下:
{
"prizes": [
{
"year": "2018",
"category": "physics",
"overallMotivation": "\"for groundbreaking inventions in the field of laser physics\"",
"laureates": [
{
"id": "960",
"firstname": "Arthur",
"surname": "Ashkin",
"motivation": "\"for the optical tweezers and their application to biological systems\"",
"share": "2"
},
{
"id": "961",
"firstname": "Gérard",
"surname": "Mourou",
"motivation": "\"for their method of generating high-intensity, ultra-short optical pulses\"",
"share": "4"
},
{
"id": "962",
"firstname": "Donna",
"surname": "Strickland",
"motivation": "\"for their method of generating high-intensity, ultra-short optical pulses\"",
"share": "4"
}
]
}
]
}
你快到了;尝试:
$.prizes..laureates[?(@.firstname == "Donna")]