gpt4 book ai didi

多个不同路径的 JSONPath 联合

转载 作者:行者123 更新时间:2023-12-03 23:52:29 37 4
gpt4 key购买 nike

我正在尝试构建一个 单个 JSONPath 查询 ,它将测试 是否存在两个或多个路径

让我们考虑以下示例文档:

{
"firstName": "John",
"lastName" : "doe",
"age" : 26,
"address" : {
"streetAddress": "naist street",
"city" : "Nara",
"postalCode" : "630-0192"
},
"phoneNumbers": [
{
"type" : "iPhone",
"number": "0123-4567-8888"
},
{
"type" : "home",
"number": "0123-4567-8910"
}
]
}

到目前为止,我发现:
$..[firstName,lastName,type]
并从整个文档中获取所有这些元素。

但是,我需要的是检查 两条不同的路径 ,例如:
 $.firstName 
$.address.city

这可以通过单个 JSONPath 查询来完成吗?我不能写这样的东西:
$.[firstName,address.city]

使用 XML 和 XPath 我可以写:
/person/firstname | /person/address/city

并获得所有匹配的 XML 元素的联合。

我可以对 JSONPath 做同样的事情吗?

最佳答案

我认为在原始 JSONPath 中最接近的是使用递归下降和联合,即

$..['firstName','city']
Goessner 实现将返回
[
"John",
"Nara"
]
kubernetes JSONPath支持对联合运算符的扩展,允许
[‘metadata.name’, ‘status.capacity’]
哪里 namecapacitymetadata 的成员和 status .
JSONMatch ,它是 JSONPath 的变体,最初基于 Kubernetes JSONPath 解析器,支持完全独立路径的联合,例如
[employee[5].name, company.name, wageTiers[compensation > 10000]]
JSONMatch 在 go 中可用我相信 javascript还。
少数 JSONPath 实现支持 bracket notation with two literals separated by dotbracket notation with two literals separated by dot without quotes .
jsoncons C++ library (自 0.161.0 起)支持完全独立路径的 JSONPath 联合与表示法
$..['firstName',@.address.city]

关于多个不同路径的 JSONPath 联合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55497833/

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