How to check json value in response body

I want to check the value and data type of event and id

ex.
var js = pm.response.json();
pm.expect(js.messages[0].message.message_value.event).to.eql(“test.completed”);
pm.expect(js.messages[0].message.message_value.data.id).to.be.a(“string”);

{
  "messages": [{
       "message": {
              "message_value": "{\"event\":\"test.completed\",\"data\":{\"id\":\"tets_32wbiwneahxa\"}}"
       }
   }]
}

Hi @YIMK

Im no expert when it comes to JSON, but I believe that to call .event and .data.id properties in this way you would need to remove the (opening and closing) quotes and backslashes from the “message_value” property like this.

{
    "messages": [
        {
            "message": {
                "message_value": {"event":"test.completed","data":{"id":"tets_32wbiwneahxa"}}
            }
        }
    ]
}

Then your assertions would work;

image

However, if that is a server response, removing the characters may not be an option.

2 Likes