Reputation: 1
Trying to parse this JSON response and get the id Value
{
"responseStatus": "SUCCESS",
"size": 1,
"start": 0,
"limit": 200,
"documents": [
{
"document": {
"id": 26,
Using this script to parse the response and post the value as an environment variable, for some reason is not retrieving the expected response.
var jsonData = JSON.parse(responseBody);
postman.setEnvironmentVariable("id", jsonData.id);
Although it created the id variable in the environment, the value is empty.
Upvotes: 0
Views: 2251
Reputation: 2355
Since the id
is under an object in the documents
array of the response, you should use this
var jsonData = JSON.parse(responseBody);
var id = jsonData.documents[0].document.id;
postman.setEnvironmentVariable("id", id);
Upvotes: 1