0
0
Postmantesting~20 mins

JSON body in Postman - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
JSON Body Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this JSON validation test?
Given this JSON body sent in a POST request, what will the test assertion result be in Postman?
Postman
{
  "user": {
    "id": 123,
    "name": "Alice",
    "roles": ["admin", "editor"]
  }
}

// Test script snippet:
pm.test("User ID is 123", () => {
  pm.expect(pm.response.json().user.id).to.eql(123);
});
ATest fails due to syntax error in JSON body
BTest fails because user.id is a string, not a number
CTest passes because user.id equals 123
DTest fails because roles array is empty
Attempts:
2 left
💡 Hint
Check the data type of user.id in the JSON body.
assertion
intermediate
2:00remaining
Which assertion correctly checks if the JSON response contains a non-empty roles array?
You want to write a Postman test to verify the roles array in the JSON response is not empty. Which assertion is correct?
Apm.expect(pm.response.json().user.roles.length).to.be.above(0);
Bpm.expect(pm.response.json().user.roles).to.eql([]);
Cpm.expect(pm.response.json().user.roles).to.be.empty();
Dpm.expect(pm.response.json().user.roles).to.have.lengthOf(0);
Attempts:
2 left
💡 Hint
Think about how to check array length is greater than zero.
locator
advanced
2:00remaining
Identify the correct JSON path to access the user's second role
Given this JSON body: { "user": { "id": 123, "name": "Alice", "roles": ["admin", "editor"] } } Which JSON path correctly accesses the second role?
Auser.roles[1]
Buser.roles.1
Cuser.roles(1)
Duser.roles[2]
Attempts:
2 left
💡 Hint
Remember JSON arrays are zero-indexed.
🔧 Debug
advanced
2:00remaining
Why does this Postman test fail when checking a JSON boolean value?
Test script: pm.test("Check active status", () => { pm.expect(pm.response.json().user.active).to.eql("true"); }); JSON response: { "user": { "active": true } } Why does the test fail?
AThe test syntax is invalid and causes a runtime error
BThe JSON response is missing the active field
CThe JSON boolean true is case-sensitive and must be "True"
DThe test compares boolean true to string "true", causing failure
Attempts:
2 left
💡 Hint
Check the data types compared in the assertion.
framework
expert
3:00remaining
Which Postman test script correctly validates that the JSON response has a 'user' object with a 'name' property of type string?
Choose the test script that correctly checks the presence and type of 'name' inside 'user' in the JSON response.
A
pm.test("User name is string", () => {
  const jsonData = pm.response.json();
  pm.expect(jsonData.user.name).to.be.string();
});
B
pm.test("User name is string", () => {
  const jsonData = pm.response.json();
  pm.expect(jsonData.user).to.have.property('name').that.is.a('string');
});
C
pm.test("User name is string", () => {
  const jsonData = pm.response.json();
  pm.expect(jsonData.user.name).to.be.a('string');
});
D
pm.test("User name is string", () => {
  const jsonData = pm.response.json();
  pm.expect(typeof jsonData.user.name).to.eql('string');
});
Attempts:
2 left
💡 Hint
Check the chaining syntax for property and type assertions in Postman.