regex - 带有正则表达式的 JSONPath 过滤器返回数组中的所有值而不是子集
问题描述
我试图弄清楚如何编写一个 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"
}
]
}
我希望这个过滤器只给我“iPhone”类型的电话号码。
$.phoneNumbers[?(@.type =~ /ne$/ )]
相反,它给了我两个电话号码。谁能告诉我为什么?
解决方案
凯蒂-抱歉延迟回答。
$..phoneNumbers[?(@['type'] == 'iPhone')].number
希望能解决这个问题。
也许这个解决方案对其他人有用。
推荐阅读
- c++ - 对于 boost::variant,是否有类似 std::visit 的 boost::visit?
- reactjs - react-router v4 中的自定义活动链接
- javascript - 如何使用 Angular 7 在 html 中显示相关数据
- php - 如何从变量上的 curl 请求中存储我的 cookie
- sql - 需要查看子查询的合并输出
- html - 使用“.map”获取选项时如何修复选择的默认值?
- r - R data.table:引用外部分配列名的数据表列
- sql - 数据库迁移 - 旧数据库到新定义的数据库
- typescript - rxjs:地图添加字段
- arrays - 在 Azure 数据工厂中将 JSON 文件从平面数组转换为嵌套数组