Bird
Raised Fist0
Postmantesting~20 mins

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

Choose your learning style10 modes available

Start learning this pattern below

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
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.

Practice

(1/5)
1. What is the primary purpose of extracting data from API responses in Postman?
easy
A. To reuse data in subsequent API requests
B. To change the API endpoint URL
C. To modify the request headers
D. To delete the response data

Solution

  1. Step 1: Understand the role of data extraction

    Extracting data allows you to capture values from one response to use later.
  2. Step 2: Connect API requests using extracted data

    This helps chain requests by passing data like tokens or IDs forward.
  3. Final Answer:

    To reuse data in subsequent API requests -> Option A
  4. Quick Check:

    Extract data = reuse in next requests [OK]
Hint: Extract data to pass info between requests [OK]
Common Mistakes:
  • Thinking extraction changes the URL
  • Confusing extraction with header modification
  • Believing extraction deletes data
2. Which Postman script correctly extracts the value of userId from a JSON response and saves it as an environment variable?
easy
A. let data = pm.response.json(); pm.environment.set('userId', data.userId);
B. pm.response.set('userId', pm.response.json().userId);
C. pm.environment.get('userId', pm.response.json().userId);
D. let userId = pm.response.set('userId');

Solution

  1. Step 1: Use pm.response.json() to parse JSON

    This method converts the response body into a JavaScript object.
  2. Step 2: Use pm.environment.set() to save variable

    Set the environment variable 'userId' with the extracted value.
  3. Final Answer:

    let data = pm.response.json(); pm.environment.set('userId', data.userId); -> Option A
  4. Quick Check:

    Parse JSON + set env variable = let data = pm.response.json(); pm.environment.set('userId', data.userId); [OK]
Hint: Use pm.response.json() then pm.environment.set() [OK]
Common Mistakes:
  • Using pm.response.set() which doesn't exist
  • Using pm.environment.get() to set variables
  • Not parsing JSON before accessing properties
3. Given the response body:
{"token": "abc123", "user": {"id": 42}}

What will this Postman script save in the environment variable authToken?
let jsonData = pm.response.json();
pm.environment.set('authToken', jsonData.token);
medium
A. null
B. 42
C. undefined
D. "abc123"

Solution

  1. Step 1: Parse the JSON response

    jsonData.token accesses the 'token' key which has value "abc123".
  2. Step 2: Set environment variable with token value

    pm.environment.set saves "abc123" as 'authToken'.
  3. Final Answer:

    "abc123" -> Option D
  4. Quick Check:

    jsonData.token = "abc123" [OK]
Hint: Access exact key from parsed JSON to get value [OK]
Common Mistakes:
  • Using user.id instead of token
  • Expecting number 42 instead of string token
  • Not parsing JSON before accessing token
4. You wrote this Postman test script to extract sessionId from the response:
let data = pm.response.json();
pm.environment.set('sessionId', data.session_id);

But the environment variable sessionId is always empty. What is the likely problem?
medium
A. pm.response.json() does not parse JSON
B. pm.environment.set() cannot save variables
C. The response JSON uses sessionId not session_id
D. You must use pm.collectionVariables.set() instead

Solution

  1. Step 1: Check JSON key names carefully

    The script uses 'session_id' but the response likely has 'sessionId' (camelCase).
  2. Step 2: Correct key name to match response

    Use data.sessionId to correctly extract the value.
  3. Final Answer:

    The response JSON uses sessionId not session_id -> Option C
  4. Quick Check:

    Key name mismatch causes empty variable [OK]
Hint: Match JSON keys exactly, including case [OK]
Common Mistakes:
  • Assuming pm.environment.set() doesn't work
  • Not parsing JSON before accessing keys
  • Confusing environment and collection variables
5. You receive this nested JSON response:
{"data": {"users": [{"id": 1, "name": "Alice"}, {"id": 2, "name": "Bob"}]}}

How do you extract and save the name of the second user as a collection variable in Postman?
hard
A. pm.environment.set('secondUserName', pm.response.json().data.users[1].name);
B. let json = pm.response.json(); pm.collectionVariables.set('secondUserName', json.data.users[1].name);
C. let json = pm.response.json(); pm.environment.set('secondUserName', json.data.users[2].name);
D. pm.collectionVariables.set('secondUserName', pm.response.json().users[2].name);

Solution

  1. Step 1: Parse the nested JSON response

    Access the array at json.data.users and select index 1 for the second user.
  2. Step 2: Save the second user's name as a collection variable

    Use pm.collectionVariables.set with key 'secondUserName' and value json.data.users[1].name.
  3. Final Answer:

    let json = pm.response.json(); pm.collectionVariables.set('secondUserName', json.data.users[1].name); -> Option B
  4. Quick Check:

    Index 1 in users array = second user name [OK]
Hint: Use zero-based index and correct variable scope [OK]
Common Mistakes:
  • Using index 2 instead of 1 for second user
  • Mixing environment and collection variables
  • Not parsing JSON before accessing nested data