cancel
Showing results for 
Search instead for 
Did you mean: 

Contains Assert to match Regex in JSON Response

Highlighted
New Contributor

Contains Assert to match Regex in JSON Response

I am new to SuapUI and I am trying to use the Contains assert to verify that a certain string exists in a response. I know I can match the value I am looking for with a JSONPath match ($.data[0].ratu_desc), but the value might not always be in the same position (0).

 

I merely want to verify that the string "ratu_desc": "Total Canada" exists in the response. 

 

What regex should I use? Even when I go to the online regex testers to test my regex pattern, when I paste the pattern into the Contains box it matches nothing.


My JSON response:
{
"data": [
{
"ratu_id": 247796211,
"ratu_desc": "Total Canada",
"ratu_code": "CAN",
"ratu_isarchived": 0,
"ratu_ratm_id": 247795404,
"ratu_ratm_id_lookup": "Audience",
"ratu_slu_id_markettype": 124330,
"ratu_slu_id_markettype_lookup": "Uses Market Allocation Methods",
"ratu_slu_id_estimatetype": null,
"ratu_slu_id_estimatetype_lookup": null
},
{
"ratu_id": 257213831,
"ratu_desc": "SQA Universe",
"ratu_code": "SQUNV",
"ratu_isarchived": 0,
"ratu_ratm_id": 247795993,
"ratu_ratm_id_lookup": "Edmonton EM",
"ratu_slu_id_markettype": 124320,
"ratu_slu_id_markettype_lookup": "Has Market Level estimates",
"ratu_slu_id_estimatetype": null,
"ratu_slu_id_estimatetype_lookup": null
},

],
"error": null,
"bvError": null
}

Tags (1)
3 REPLIES 3
Highlighted
Community Leader

Re: Contains Assert to match Regex in JSON Response

@mehdihs : You can write custom script assertion i think with pre-available features it is not possible.

 

 


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
Highlighted
New Contributor

Re: Contains Assert to match Regex in JSON Response

if the regex can't match a string in a response, what does it actually do?

Highlighted
Community Hero

Re: Contains Assert to match Regex in JSON Response

Hey @mehdihs,

I think the contains assertion only works for xpath (xml), not jsonpath (json).

So the regex does work, but only for xml.

Im not sure but i think i remember trying this before and ending up having to use a script assertion instead.

Ta

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
New Here?
Join us and watch the welcome video:
Top Kudoed Authors