Complete the code to set a variable from the JSON response in Postman.
pm.environment.set('userId', pm.response.json().[1]);
The correct key to extract the user ID from the JSON response is id. This sets the environment variable userId to that value.
Complete the code to set a global variable from a nested JSON response property.
pm.globals.set('authToken', pm.response.json().data.[1]);
data.The token is nested inside the data object under the key token. This sets the global variable authToken correctly.
Fix the error in the code to correctly set a variable from an array in the response.
pm.environment.set('firstItem', pm.response.json().items[[1]]);
Array indexes start at 0 in JavaScript. To get the first item, use index 0.
Fill both blanks to set a variable from a nested array object property in the response.
pm.collectionVariables.set('email', pm.response.json().users[[1]].[2]);
name instead of email.The first user is at index 0 in the users array, and the email property is email.
Fill all three blanks to set a variable from a deeply nested JSON response property.
pm.environment.set('city', pm.response.json().[1][[2]].address.[3]);
profiles.city.The city is inside the address of the third user (index 2) in the users array.