cancel
Showing results for 
Search instead for 
Did you mean: 

JSON path and case insensitive search

Don
New Contributor II

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.

4 REPLIES 4

SpiroTaleski
Valued Contributor

@Don 

Find the attached sample pipeline. It uses array filter function for filtering the elements. 

Hope it will helps. 

 

Don
New Contributor II

While this would be a functional workaround, I was hoping to perform the whole operation through a purely jsonPath query.

SpiroTaleski
Valued Contributor

Not sure if JSONPath itself natively support case-insensitive comparison or regex matching directly(considering that it only returns single value). 

Don
New Contributor II

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.