Resolved: How to match content in json response in Postman?

In this post, we will see how to resolve How to match content in json response in Postman?


Been trying to figure how to get regex working in Postman, but can’t seem to zone in on what I’m doing wrong.
With the example below, I can get the ID fine when checking for an exact match, email size is 74004. But I’ve been trying to check for partials, like if the subject has a word, example instead of checking the email size, to check if the subject contains the word “Resource”, or even via regex matching.
Tried pm.expect(counter.metadata.email_subject).contains(“Password”); and also pm.expect(counter.metadata.email_subject).to.match(/Password/); but always get an error.
and then you can match the JSON body by putting your regex as the argument to the .to.match() function, e.g. this should pass

If you have better answer, please add a comment about this, thank you!