How to get properties from a nested object inside of an already nested object in tests?

Your question may already have an answer on the community forum. Please search for related topics, and then read through the guidelines before creating a new topic.

Here’s an outline with best practices for making your inquiry.

My question: How to grab a value from a nested object inside of an already nested object and see if it is equal to the expected error message

Details (like screenshots):

How I found the problem:

I’ve already tried:
pm.test(“name no good”,function () {

let response = pm.response.json();

let name = _.get(response, 'errorResult.errorMessages')

pm.expect(name.name).to.contain("'Name' must not be empty.")

}); and
pm.test(“name no good”,function () {

let response = pm.response.json();

let name = _.get(response, 'errorResult.errorMessages.name')

pm.expect(name).to.eql("'Name' must not be empty.")

});

Hey @liamkruger62 Welcome to the community :wave:

If you still haven’t found the solution,
For nested objects, you can try saving the objects into variables and then performing the tests on the variable.
You can try to use this logic:

var jsonData= pm.response.json();
var errorResults= jsonData.errorResult;
var errorMessages= errorResults.errorMessages;
//...now you can perform the tests
pm.expect(errorMessages.name).......

Good luck!