[英]JSONata Filter Array by starts-with criteria
I'm pretty new to JSONata, and I need to write a query that will search/filter an array and return only the values that meet the criteria.我是 JSONata 的新手,我需要编写一个查询来搜索/过滤数组并仅返回满足条件的值。 Specifically:具体来说:
{
"data": [
{
"externalIds": [
"005262615581",
"1395464646",
"566955222",
"6696630050055999",
"99506533221233"
],
"firstName": "Brian",
"id": "a91f91af91af91a9f11fakeid",
"lastName": "lastName",
"office": null,
"phone": null,
"role": "Admin",
}
]
}
I've tried $Contains, and $Filter, but I honestly don't know the syntax to accomplish the "starts-with" concept.我试过 $Contains 和 $Filter,但老实说我不知道实现“starts-with”概念的语法。 I need to filter the "externalIds" array and only return the IDs that begin with 005, NOT contain 005. So in this body I need it to return "005262615581".我需要过滤“externalIds”数组,只返回以 005 开头的 ID,不包含 005。所以在这个正文中我需要它返回“005262615581”。
You can use regular expressions and the $match function :您可以使用正则表达式和$match function :
data.externalIds[$match($, /^005/)]
See it live on the playground: https://stedi.link/fa5C2GZ在游乐场观看直播: https://stedi.link/fa5C2GZ
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.