Forum Discussion

mehdihs's avatar
mehdihs
New Contributor
4 years ago

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
}

4 Replies

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

     

     

    • mehdihs's avatar
      mehdihs
      New Contributor

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

      • richie's avatar
        richie
        Community Hero
        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