I have an API that returns an JSON array of objects, where one of fields contains escaped JSON. Let's say it looks like that:
{
"results":[
{
"id": "id-1",
"data": "{\"name\", \"Adam\", \"surname\": \"Parker\"}"
},
{
"id": "id-2",
"data": "{\"name\", \"Adam\", \"surname\": \"Parker-Bates\"}"
},
{
"id": "id-3",
"data": "{\"name\", \"Adam Robert\", \"surname\": \"Parker\"}"
}
]
}
Now, I need to assert that that array contains exactly one element matching given criteria, let's say I'm looking for Adam Parker. If it would be returned as a proper JSON object it would be pretty straightforward. I could search for substrings, but it can give me false results. Maybe I could look for certain regular expressions to match only \"Adam\" and "\Parker\" but would prefer to convert that strings to JSON objects, since real case scenario has much more complex, nested data. Is there any way to do it with karate? I do not need ids, so I can extract data to array of strings if that would make it easier.