gpt4 book ai didi

jsonpath - 使用 jsonpath 获取父节点

转载 作者:行者123 更新时间:2023-12-03 23:27:45 55 4
gpt4 key购买 nike

使用节点 JSONPath,如何从子节点值中获取父节点名称

{
"store": {
"book": [
{
"id":"1",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{
"id":"2",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
}
]
}
}


我用这个表达式根据值来识别子节点,我想用这个子节点来找到父节点
$.[?(@.id =="1")]

最佳答案

您没有指定 JSON Path 的哪个实现,但是对于 Gatling (Scala) 和 JayWay (Java),您可以使用嵌套过滤器在返回父级、祖父级或其他任何内容的同时按子级过滤。这是一个示例:

使用这个 JSON:

{
"a": {
"b": {
"c": {
"d": {
"e": "foo"
}
},
"something": "bar"
}
}
}

而这条路:
$.a.b[?(@.c[?(@.d[?(@.e == "foo")])])].something

返回:
[ "bar" ]

我可以检索 b通过使用表达式到达较低的节点作为过滤器。

其他一些实现在这些表达式上出错。

关于jsonpath - 使用 jsonpath 获取父节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41878757/

55 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com