I have a well formatted json like below:
{
"Slide":[
{
"Code": "'!!!",
"Status": "OK"
},
{
"Code": "123",
"Status": "Failed"
}
]
}
I use json path to filter Status
based on Code
.
The Jsonpath is like this : ..[?(@.Code == '{0}')].Status
in C#.
So programmatically parameter in jpath is populated.
When value "'!!!" is passed to above jpath( i.e ..[?(@.Code == ''!!!')].Status
) it'll not work, as single quote is not escaped. Since I'm, not hardcoding parameter value I cannot escape it manually.
i.e ..[?(@.Code == '\'!!!')].Status
will solve the problem. But I need to achieve it programmatically.
One way to approach this is to use a regex and identify the pattern and escape it before passing the parameter to jpath. I'm not so good with regex and couldn't write one which will keep beginning and ending quote of jpath intact while replacing. Could anyone please help.
Or is there any better way to approach?..
P.s: I can't use regex feature of jpath as I need to filter by specific code.