0
0
Postmantesting~5 mins

JSON value assertions in Postman - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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()
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()
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
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
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
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.