11-14-2024 02:27 PM
I'm having issues trying to find all instances that match a particular email address using JSONPath. The example below is just an array of email objects, but the real data is an array or personnell profiles that I need to search by an email address that has random capitalization in it.
Example data:
{ "data": [
{"email": "yomomma@notreal.com" },
{ "email": "yoyoma@notreal.com" },
{ "email": "yoyomama@notreal.com" },
{"email": "someOtherEmail@notreal.com" },
{ "email": "YoMomma@notreal.com" },
{ "email": "General@frustration.com" },
{ "email": "ILike@cookies.com" } ] }
I can get a single value out by using:
jsonPath($data, "$[?(@.email == 'yomomma@notreal.com')]")
Extending that using the regex syntax used elsewhere made me think that this should find all instances:
jsonPath($data, "$[?(@.email =~/yomomma@notreal.com/i )]")
No luck.
An alternate format (Goessner I believe) didn't work either:
jsonPath($data, "$[?(/yomomma@notreal.com/i.test(@.email))]")
Any help would be greatly appreciated.
11-15-2024 01:37 AM
Find the attached sample pipeline. It uses array filter function for filtering the elements.
Hope it will helps.
a month ago
While this would be a functional workaround, I was hoping to perform the whole operation through a purely jsonPath query.
a month ago
Not sure if JSONPath itself natively support case-insensitive comparison or regex matching directly(considering that it only returns single value).
a month ago
Case insensitivity in native JSONpath is based on the engine. The example from the first message in the thread :
[?(@.email =~/yomomma@notreal.com/i )]
[?(/yomomma@notreal.com/i.test(@.email))]
are from two of the libraries supported in jsonquerytoole.com (dchester and Goessner).
I have no idea which one Snaplogic is using, but I'm guessing neither of those as those examples don't work.