Challenge - 5 Problems
JSON Body Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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);
});Attempts:
2 left
💡 Hint
Check the data type of user.id in the JSON body.
✗ Incorrect
The JSON body has user.id as a number 123, matching the assertion exactly, so the test passes.
❓ assertion
intermediate2: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?
Attempts:
2 left
💡 Hint
Think about how to check array length is greater than zero.
✗ Incorrect
Option A correctly asserts the roles array length is greater than zero, meaning it is not empty.
❓ locator
advanced2: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?
Attempts:
2 left
💡 Hint
Remember JSON arrays are zero-indexed.
✗ Incorrect
Option A uses correct zero-based indexing to access the second element at index 1.
🔧 Debug
advanced2: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?
Attempts:
2 left
💡 Hint
Check the data types compared in the assertion.
✗ Incorrect
The test compares boolean true with string "true", which are different types, so the assertion fails.
❓ framework
expert3: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.
Attempts:
2 left
💡 Hint
Check the chaining syntax for property and type assertions in Postman.
✗ Incorrect
Option B uses Chai's 'have.property' with 'that.is.a' chaining correctly to check property existence and type.