I am trying to parse JSON data via Set Variables with prefix to JSON with the following text:
{
"SearchString" : "\w+"
}
I switched options to "Process nothing" but get an error when I try the action.
I only get it processed when I escape the backslash and use "Process nothing":
{
"SearchString" : "\\w+"
}
But in this case I have a double backslash in the result, which I do not want.
Is this as expected? Maybe I get the option wrong?
Kind regards
Your JSON is invalid. A slosh cannot be followed by a w in a JSON string.
You need to switch the options to Process Nothing, and also you need to double the slosh to be a valid JSON string.
Hi Peter,
Thanks for the quick reply. Oops invalid JSON, RFC 8259, I see.
I wanted to put a bunch of variables in a more convenient JSON array, I will have to put some more thought into it.
Escaping works, just makes it more difficult to edit and debug.
Thanks!
I encountered the same problem. Where I'm trying to use JSON to store a bunch of variables. One of the variables will be a string which will be processed later as a regular expression. And another variable would be a string constructed from other variable values.
In my case I needed to keep the "Process text normally" set for other variables.
My regular expression included the \s
construct. I found escaping the backslash into \\s
wasn't enough. I had to double-double escape the backslash so \s
turned into \\\\s
.
Once I did this then I could store the regular expression in JSON and I could later use the value from JSON for matching. All while keeping "Process Text Normally" set.
JSON with Regex value.kmmacros (3.6 KB)