Comparing strings containing single quotes with Response body: Contains string snippet

This is my function

My response body

I keep getting a FAIL. I tried escaping the single quotations, and it didn’t help.
When I test just the first word of the string, I get a pass.

Hi @marina-biro

Your response body is JSON so you should use pm.response.json().
Your response is also an array, so you will need to specify the array index, in this response, there is only 1 object so your index would be [0] (all arrays start at 0).
And inside this object, the string you are trying to match is stored in the value of the “message” property.

your code should look something like this;

const response = pm.response.json();

pm.test("my test", function(){
    pm.expect(response[0].message).to.include("my 'example' sentence 'with' single quotes.");

Thank you for the explanation :slight_smile:

You could probably do it by parsing text, but I just think it would be much harder when you can use the JSON properties.

1 Like