Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is a JSON value assertion in Postman?
It is a check in Postman tests that verifies if a specific value in the JSON response matches the expected value.
Click to reveal answer
beginner
How do you access a JSON value in Postman test scripts?
Use `pm.response.json()` to parse the response, then access values like `jsonData.key` or `jsonData['key']`.
Click to reveal answer
beginner
Example of a simple JSON value assertion in Postman?
```javascript
const jsonData = pm.response.json();
pm.test('Check user name', () => {
pm.expect(jsonData.name).to.eql('John');
});
``` This checks if the 'name' value is 'John'.
Click to reveal answer
beginner
What happens if a JSON value assertion fails in Postman?
The test will show as failed in the Postman test results, helping you identify issues in the API response.
Click to reveal answer
beginner
Why use JSON value assertions in API testing?
To ensure the API returns correct and expected data, improving reliability and catching errors early.
Click to reveal answer
Which Postman method parses the JSON response body?
Apm.response.body()
Bpm.response.text()
Cpm.response.json()
Dpm.request.json()
✗ Incorrect
pm.response.json() parses the response body as JSON so you can access its values.
How do you assert that a JSON key 'status' equals 'success' in Postman?
Apm.expect(jsonData.status).to.eql('success')
Bpm.expect(jsonData.status).to.be.true()
Cpm.expect(jsonData.status).to.exist()
Dpm.expect(jsonData.status).to.be.null()
✗ Incorrect
Use to.eql('success') to check exact value equality.
What does a failed JSON value assertion indicate?
AThe API response value did not match the expected value
BThe API is down
CThe test script has syntax errors
DThe JSON response is empty
✗ Incorrect
A failed assertion means the actual value differs from what was expected.
Which of these is a best practice for JSON value assertions?
ACheck every key in the JSON response
BCheck only the keys you need to verify
CIgnore JSON structure and check text only
DUse random values for assertions
✗ Incorrect
Checking only necessary keys keeps tests focused and efficient.
In Postman, where do you write JSON value assertions?
AIn the Body tab
BIn the Pre-request Script tab
CIn the Headers tab
DIn the Tests tab of the request
✗ Incorrect
The Tests tab is where you write scripts to check response values.
Explain how to write a JSON value assertion in Postman to check if a response key 'age' equals 30.
Think about parsing JSON and using pm.expect to compare values.
You got /4 concepts.
Describe what happens when a JSON value assertion fails during a Postman test run.
Consider how Postman shows test results.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of JSON value assertions in Postman?
easy
A. To send requests to the server
B. To check if the API response data matches expected values
C. To format JSON data for display
D. To create new API endpoints
Solution
Step 1: Understand JSON value assertions
JSON value assertions verify that the data returned by an API is correct and matches what is expected.
Step 2: Identify the purpose in Postman
In Postman, assertions are used to check API responses, not to send requests or format data.
Final Answer:
To check if the API response data matches expected values -> Option B
Quick Check:
Assertions verify response data = A [OK]
Hint: Assertions check response data correctness fast [OK]
Common Mistakes:
Confusing assertions with sending requests
Thinking assertions format JSON
Believing assertions create APIs
2. Which of the following is the correct syntax to assert that the JSON response has a key 'status' with value 'success' in Postman?
easy
A. pm.expect(response.status).to.equal('success');
B. pm.response.json().status == 'success';
C. pm.expect(pm.response.json().status).to.eql('success');
D. assert(pm.response.status == 'success');
Solution
Step 1: Identify correct assertion syntax in Postman
Postman uses pm.expect() with the JSON response accessed by pm.response.json(). The method to check equality is .to.eql()
Step 2: Eliminate incorrect options
pm.expect(pm.response.json().status).to.eql('success'); correctly uses pm.expect(pm.response.json().status).to.eql('success'); The other options have syntax errors or incorrect usage such as wrong response reference, missing pm.expect, or invalid functions.
Final Answer:
pm.expect(pm.response.json().status).to.eql('success'); -> Option C
Quick Check:
pm.expect + pm.response.json() + .to.eql() = D [OK]
Hint: Use pm.expect with pm.response.json() and .to.eql() [OK]
But the test always fails even when the API returns { "data": { "status": "active" } }. What is the likely problem?
medium
A. The assertion should use .to.eql() for deep equality
B. The response JSON is not parsed correctly
C. Using .to.equal() instead of .to.eql() for object comparison
D. The test is missing pm.response.json() call
Solution
Step 1: Understand difference between .to.equal() and .to.eql()
.to.equal() checks strict equality for primitives but can fail for objects or deep checks. .to.eql() is used for deep equality including strings and objects.
Step 2: Identify the correct assertion for object value
Since 'data' is an object, .to.eql() is required for deep equality checks. Using .to.equal() performs strict reference equality (===), which fails for distinct object instances even if contents match.
Final Answer:
The assertion should use .to.eql() for deep equality -> Option A
Quick Check:
Use .to.eql() for object equality in JSON assertions [OK]
Hint: Use .to.eql() for JSON value assertions, not .to.equal() [OK]
Common Mistakes:
Confusing .to.equal() and .to.eql()
Assuming JSON parsing failed
Missing pm.response.json() call
5. You want to assert that the API response JSON contains an array 'items' where each item has a 'price' greater than 0. Which Postman test code correctly checks this?
hard
A. pm.expect(pm.response.json().items.filter(price > 0)).to.not.be.empty;
B. pm.expect(pm.response.json().items).to.have.property('price').above(0);
C. pm.expect(pm.response.json().items.price).to.be.above(0);
D. pm.expect(pm.response.json().items.every(item => item.price > 0)).to.be.true;
Solution
Step 1: Understand the requirement
We need to check that every item in the 'items' array has a 'price' greater than 0.
Step 2: Analyze each option
pm.expect(pm.response.json().items.every(item => item.price > 0)).to.be.true; uses JavaScript's every() method to check all items satisfy price > 0, then asserts true. This is correct. pm.expect(pm.response.json().items).to.have.property('price').above(0); incorrectly tries to check property on array directly. pm.expect(pm.response.json().items.price).to.be.above(0); tries to access items.price which is invalid since items is an array. pm.expect(pm.response.json().items.filter(price > 0)).to.not.be.empty; uses filter incorrectly without a function.
Final Answer:
pm.expect(pm.response.json().items.every(item => item.price > 0)).to.be.true; -> Option D
Quick Check:
Use every() with pm.expect to check all array items [OK]
Hint: Use .every() to assert all array items meet condition [OK]