Verify JSON response values in Postman
Preconditions (2)
✅ Expected Result: The response status is 200 and all JSON fields have the expected values
Jump into concepts and practice - no test required
pm.test('Status code is 200', () => { pm.response.to.have.status(200); }); const jsonData = pm.response.json(); pm.test('Name is John Doe', () => { pm.expect(jsonData.name, 'Check name field').to.eql('John Doe'); }); pm.test('Age is 30', () => { pm.expect(jsonData.age, 'Check age field').to.eql(30); }); pm.test('Roles include admin', () => { pm.expect(jsonData.roles, 'Check roles array').to.include('admin'); });
This Postman test script first checks the HTTP status code is 200 using pm.response.to.have.status(200). Then it parses the JSON response once with pm.response.json() and stores it in jsonData for reuse.
Each field is checked with pm.expect assertions: the name field must equal 'John Doe', the age field must equal 30, and the roles array must include the string 'admin'.
Descriptive messages are added to each assertion to help understand failures.
Now add data-driven testing with 3 different user IDs and verify their names and ages
const jsonData = pm.response.json(); pm.expect(jsonData.user.id).to.eql(12345);
{ "user": { "id": 12345, "name": "Alice" } }?pm.expect(pm.response.json().data).to.equal({"status": "active"});{ "data": { "status": "active" } }. What is the likely problem?