0
0
Postmantesting~20 mins

Extracting data from responses in Postman - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Response Extraction Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Extracting a single value from JSON response
Given the following Postman test script, what will be the value of userId after execution if the response body is {"user":{"id":42,"name":"Alice"}}?
Postman
const responseJson = pm.response.json();
const userId = responseJson.user.id;
A"42"
Bundefined
Cnull
D42
Attempts:
2 left
💡 Hint
Remember that JSON numbers are parsed as numbers, not strings.
assertion
intermediate
2:00remaining
Correct assertion to check extracted value
Which Postman test assertion correctly verifies that the extracted token from the JSON response {"auth":{"token":"abc123"}} is exactly "abc123"?
Postman
const responseJson = pm.response.json();
const token = responseJson.auth.token;
Apm.test('Token is abc123', () => { pm.expect(token).to.be.a('number'); });
Bpm.test('Token is abc123', () => { pm.expect(token).to.be.true; });
Cpm.test('Token is abc123', () => { pm.expect(token).to.eql('abc123'); });
Dpm.test('Token is abc123', () => { pm.expect(token).to.have.length(5); });
Attempts:
2 left
💡 Hint
Check the exact value and type of the token string.
🔧 Debug
advanced
2:30remaining
Debugging extraction from nested JSON array
You want to extract the id of the first item in the items array from this response: {"data":{"items":[{"id":10},{"id":20}]}}. The code below returns undefined. What is the problem?
Postman
const responseJson = pm.response.json();
const firstItemId = responseJson.items[0].id;
AThe code should access responseJson.data.items[0].id instead of responseJson.items[0].id.
BThe responseJson is not parsed correctly; use pm.response.text() instead.
CThe items array is empty, so accessing index 0 returns undefined.
DThe id property does not exist on the items objects.
Attempts:
2 left
💡 Hint
Check the full path to the items array in the JSON structure.
🧠 Conceptual
advanced
2:00remaining
Understanding Postman environment variable extraction
Which statement correctly describes how to extract a value from a JSON response and save it as an environment variable in Postman?
AUse pm.environment.set('varName', value) after extracting the value from pm.response.json().
BUse pm.variables.get('varName') to save the extracted value.
CUse pm.response.save('varName', value) to store the value.
DUse pm.request.set('varName', value) to save the extracted value.
Attempts:
2 left
💡 Hint
Remember the method to set environment variables in Postman scripts.
framework
expert
3:00remaining
Choosing the correct Postman test script for conditional extraction
You want to extract the sessionId from the response only if the status code is 200. Which Postman test script correctly implements this conditional extraction?
Aif (pm.response.statusCode === 200) { const sessionId = pm.response.json().sessionId; pm.environment.set('sessionId', sessionId); }
Bif (pm.response.code === 200) { const sessionId = pm.response.json().sessionId; pm.environment.set('sessionId', sessionId); }
Cif (pm.response.code == '200') { const sessionId = pm.response.json().sessionId; pm.environment.set('sessionId', sessionId); }
Dif (pm.response.status === 200) { const sessionId = pm.response.json().sessionId; pm.environment.set('sessionId', sessionId); }
Attempts:
2 left
💡 Hint
Check the exact property name for status code in Postman response object.