0
0
Postmantesting~20 mins

Nested object assertions in Postman - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Nested Assertion Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
assertion
intermediate
2:00remaining
Check nested property value in JSON response
Given the following JSON response, which Postman test assertion correctly verifies that the user's city is 'New York'?
Postman
{
  "user": {
    "id": 123,
    "name": "Alice",
    "address": {
      "city": "New York",
      "zip": "10001"
    }
  }
}
Apm.test('City is New York', () => { pm.expect(pm.response.json().user.city).to.eql('New York'); });
Bpm.test('City is New York', () => { pm.expect(pm.response.json().user.address.city).to.eql('New York'); });
Cpm.test('City is New York', () => { pm.expect(pm.response.json().address.city).to.eql('New York'); });
Dpm.test('City is New York', () => { pm.expect(pm.response.json().user.address.zip).to.eql('New York'); });
Attempts:
2 left
💡 Hint
Remember to follow the exact path to the nested property in the JSON structure.
assertion
intermediate
2:00remaining
Verify array length inside nested object
You receive this JSON response. Which assertion correctly checks that the user has exactly 3 phone numbers?
Postman
{
  "user": {
    "phones": ["123-4567", "234-5678", "345-6789"]
  }
}
Apm.test('User has 3 phones', () => { pm.expect(pm.response.json().user.phones).to.have.lengthOf(3); });
Bpm.test('User has 3 phones', () => { pm.expect(pm.response.json().phones.length).to.eql(3); });
Cpm.test('User has 3 phones', () => { pm.expect(pm.response.json().user.phones.length).to.eql(3); });
Dpm.test('User has 3 phones', () => { pm.expect(pm.response.json().user.phones).to.eql(3); });
Attempts:
2 left
💡 Hint
Use the correct Chai assertion to check array length.
Predict Output
advanced
1:30remaining
Output of nested object assertion with missing property
What will be the result of this Postman test if the JSON response is missing the 'email' property inside 'user'?
Postman
pm.test('User email exists', () => {
  pm.expect(pm.response.json().user.email).to.exist;
});
ATest is skipped automatically
BTest passes because 'email' is optional
CTest throws a runtime error due to accessing undefined property
DTest fails with assertion error because 'email' is undefined
Attempts:
2 left
💡 Hint
Check how Chai's 'to.exist' behaves with undefined values.
🔧 Debug
advanced
2:00remaining
Identify error in nested object assertion code
This Postman test is intended to check if the user's first hobby is 'reading'. What is the error in the code?
Postman
pm.test('First hobby is reading', () => {
  pm.expect(pm.response.json().user.hobbies[0] === 'reading');
});
AMissing assertion method like 'to.eql' causes test to always pass
BIncorrect property path to hobbies array
CUsing '===' inside pm.expect causes syntax error
DNo error, test is correct
Attempts:
2 left
💡 Hint
pm.expect needs a matcher method to assert values.
framework
expert
3:00remaining
Best practice for nested object assertions in Postman tests
Which approach is best to safely assert a deeply nested property 'user.profile.contact.email' exists and equals 'test@example.com' without causing runtime errors if intermediate properties are missing?
Apm.expect(pm.response.json().user.profile.contact.email).to.eql('test@example.com');
Bif(pm.response.json().user && pm.response.json().user.profile && pm.response.json().user.profile.contact) { pm.expect(pm.response.json().user.profile.contact.email).to.eql('test@example.com'); }
Cconst email = _.get(pm.response.json(), 'user.profile.contact.email'); pm.expect(email).to.eql('test@example.com');
Dpm.expect(pm.response.json()?.user?.profile?.contact?.email).to.eql('test@example.com');
Attempts:
2 left
💡 Hint
Consider safe access methods to avoid runtime errors in nested assertions.