JSON路径表达式中的JSON路径评估



我有一个非常简单的json:

{
"authors": [
{
"id": 1,
"name": "Douglas Adams"
},
{
"id": 2,
"name": "John Doe"
}
],
"books": [
{
"name": "The Hitchhiker's Guide to the Galaxy",
"author_id": 1
}
]
}

我想询问";《银河系漫游指南》;。我尝试过这种JSON路径,但它不起作用:

$.authors[?(@.id == $.books[?(@.name == "The Hitchhiker's Guide to the Galaxy")].author_id)].name

我尝试的所有在线工具都指示了一个语法错误,这似乎是由于我的过滤器中存在JSON路径。

有人能帮我找出哪里错了,什么是正确的语法吗?

谢谢!

运行此过滤器时

$.books[?(@.name == "The Hitchhiker's Guide to the Galaxy")].author_id

它返回一个数组而不是一个值:

[
1
]

当您传递一个数组以与id:的值进行比较时,会发生语法错误

$.authors[?(@.id == {the array value}].author_id)].name

但是,您可能无法使用JSONPath提取值,这取决于您使用的语言。请参阅使用JSONPath 从JSON对象获取单个值

最新更新