JSON RegEx confusion

  • 5 December 2018
  • 4 replies
  • 3 views

Badge +8

Expression: (?<="FacilityId":")[dw-]+(?=",)

I also tried: (?<="FacilityId":")([^"]*)(?=")

Input: {"FacilityId":1,"PatientId":2323,"FirstName":"TEST"

Result: No matches

I'm trying to parse some returned JSON but I'm having a hard time doing so. I need an expression that will return the value of 1 from FacilityId, or value 2323 from PatientId. 

I looked at some other posts in the Nintex forums and thought I was getting somewhere but I can't seem to get it 100%. Can someone help me clear this up?


4 replies

Badge +7

It would help to know a little more about your data, but I did come up with something that may work for you.

I've never liked lookahead or lookbehind regex. I read that it should work in the RegEx action, but it definitely doesn't work JavaScript. 

Maybe try this:

[^{"A-z":,]d{0,4}

Here's the RegexTester link to show how it works: Parse JSON - Regex Tester/Debugger 

As long as the values you're trying to return are always numbers, this should work. If they can be longer than four digits, you can increase the {0,4} to whatever you need.

Userlevel 5
Badge +13

You could also use the patterns below with the RegEx action.

(?<=FacilityId"":)[^,]+‍
(?<=PatientId"":)[^,]+‍

You would need one Regular Expression action for each pattern above.  Each result would need to be stored in a collection variable, then retrieved using a Collection Operation action and stored in a workflow variable.

Badge +8

Just to answer my own question here:

(?<="FacilityId":)(?<FacilityId>[dw-]+)(?=,)

Badge +8

Yea, I found out the collection bit the other day. A little odd that it won't let you return the item to a single variable.

Reply