[英]Select a JSON attribute based on other elements within an array using JSONPath
I have a sample JSON array:我有一个示例 JSON 数组:
{
"data": {
"list": [
{
"id": 192,
"name": "John Black",
"username": "jblack",
"email": "jblack@myorganization.com",
"extern_uid": "user distinguished name"
},
{
"id": 63,
"name": "Jane Doe",
"username": "jadoe",
"email": "jadoe@myorganization.com",
"extern_uid": "user distinguished name"
}
]
}}
I want to extract an attribute based on another attribute using JSONPath expression,我想使用 JSONPath 表达式提取基于另一个属性的属性,
For example:例如:
I want to search for the name "Jane Doe" and extract values from the Jane Doe array like id: 63 or any other value in the Jane Doe array.我想搜索名称“Jane Doe”并从 Jane Doe 数组中提取值,例如id: 63或 Jane Doe 数组中的任何其他值。 Is this possible in JSONPath?
这在 JSONPath 中可能吗? I am not an expert in JSONPath so I apologize if this may seem trivial for others
我不是 JSONPath 的专家,所以如果这对其他人来说似乎微不足道,我深表歉意
Thanks all谢谢大家
found the solution:找到了解决办法:
$.data.list[?(@.username == "jblack")].id $.data.list[?(@.username == "jblack")].id
Will return:将返回:
"id": 192 “身份证”:192
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.