cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
ericute
Nintex Newbie

Data with escaped double quotes from JSON response parsed as a string using Regex

Jump to solution

I'm following the guide here on how to parse JSON response from a REST call to sharepoint: Parsing JSON returned from a REST service in Nintex workflow. It works as expected when the values being extracted do not contain double quotes. The problem happens when there's a double quote in the string I am extracting. 

 

Regex used: (?<="title":")([^"]*)(?=")

 

Scenario 1: No double quotes

Data to process: {"d":{"results":["title":"This is a title"]}}

Result: This is a title --> Passed

Scenario1.png

 

Scenario 2: With double quotes

Data to process: {"d":{"results":["title":"This is a \"pseudo\" title"]}}

Result using the regex above: This is a \ --> Failed

Scenario2.png

 

I tried a lot of regex combination to handle such cases but when I try it using "Run Now", I get this result: [Command executed successfully.]

 

How do I handle such cases? I need to extract the whole string first before handling character escaping. I tried looking for other helpful tips but I can't make them work as well: Parse JSON Custom Action.

 

Environment:

  • SharePoint 2013
  • Nintex Workflow (on-premise)

 

Labels: (1)
0 Kudos
Reply
6 Replies
emha
Nintex Newbie

Re: Data with escaped double quotes from JSON response parsed as a string using Regex

Jump to solution

try following pattern

 

(?<="title":")(.*)(?="[,\]}\s])

 

i.jpg

Reply
ericute
Nintex Newbie

Re: Data with escaped double quotes from JSON response parsed as a string using Regex

Jump to solution

Thanks for helping me out! The solution covers the double quotes. However, I forgot to mention that sometimes, users do not include a title since it is not required. When that happens, I get the [Command executed successfully.] response again see below.

Scenario3.png

Is it possible to handle this scenario in the same regex? If not, how to best handle this case?

0 Kudos
Reply
emha
Nintex Newbie

Re: Data with escaped double quotes from JSON response parsed as a string using Regex

Jump to solution

and what output would you expect?

the message means the action executed but there is no match (resp. it matched an empty string)

 

i.jpg

 

0 Kudos
Reply
ericute
Nintex Newbie

Re: Data with escaped double quotes from JSON response parsed as a string using Regex

Jump to solution
I am expecting a blank string. Does the "[Command executed successfully.]" return a blank string? That's something I haven't tried.
0 Kudos
Reply
emha
Nintex Newbie

Re: Data with escaped double quotes from JSON response parsed as a string using Regex

Jump to solution

let's try in runtime Smiley Happy 

Reply
ericute
Nintex Newbie

Re: Data with escaped double quotes from JSON response parsed as a string using Regex

Jump to solution

I modified the regex a bit further. Basically, there's a lot of fields to be extracted and I was able to extract them all based on your suggested solution. Also, I was able to capture blank titles as well thanks to your responses.

 

Suggested regex:

(?<="title":")(.*)(?="[,\]}\s])

Final Regex:

(?<="title":")(.*)(?=","anotherField)

It was fortunate that JSON will always return "," anotherField format and that became the prefix of when I will be cutting the data. Since double quotes are getting escaped, I was able to capture the start and end of the values I am getting. Please note that it is only applicable for JSON keys that aren't the last in the JSON object since there is no "anotherField" for the last key. Since I don't need the value of the last key, I did not include it in my handling.

 

Thanks a lot for your help!

0 Kudos
Reply