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. 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. 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".
You can use regular expressions and the $match function :
data.externalIds[$match($, /^005/)]
See it live on the playground: https://stedi.link/fa5C2GZ
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.