YIMK
May 3, 2022, 7:59am
1
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\"}}"
}
}]
}
w4dd325
(w4dd325)
May 3, 2022, 11:28am
2
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;
However, if that is a server response, removing the characters may not be an option.
2 Likes