Forum Discussion

andrew_net's avatar
andrew_net
Occasional Contributor
9 years ago
Solved

How do I assert one of the objects in an array meets a condition in SoapUI by using JSONPath

Let's say I have a response like below   {"errors": [{    "code": "100",    "message": "Message for 100",   },   {    "code": "200",    "message": "Message for 200",   } ]}   I can assert...
  • Ton646's avatar
    9 years ago

    That is a problem we have struggled with as well - I think this solution will work too, if you use expected result '100' for the following jsonpath, it should evaluate true if code 100 is present in the sample json. Basically it is asking to return the code value for any errors element where the .code subelement equals 100...  Of course this will run into problems if there can be multiple errors.code items in the json, but it has proved very useful in our tests.

     

     

    $..errors[?(@.code==100)].code

     

     

    Json used

    {"errors": [{
    "code": "100",
    "message": "Message for 100"
    },
    {
    "code": "200",
    "message": "Message for 200"
    }
    ]}