Answer the question
In order to leave comments, you need to log in
How to get value from json postman?
{
"args": {},
"data": "{\"userId\": 777, \"username\": \"Bob\"}",
"files": {},
"form": {},
"headers": {
"x-forwarded-proto": "https",
"x-forwarded-port": "443",
"host": "postman-echo.com",
"x-amzn-trace-id": "Root=1-5f0b0dea-dccf35429759ee425a86bd98",
"content-length": "34",
"content-type": "text/plain",
"user-agent": "PostmanRuntime/7.26.1",
"accept": "*/*",
"postman-token": "a7fa3df7-4bf3-4c58-a5e8-3604fbdf6dbc",
"accept-encoding": "gzip, deflate, br",
"cookie": "sails.sid=s%3AWjeqmvVrZYK5CLY3wWe7XWC6GxGTs_r4.upPw2jg33xMY%2BpNuh5xwTnMCna4YNzj24o48ukBawaA"
},
"json": null,
"url": "https://postman-echo.com/post"
}
pm.response.json().data.userId
, returnsundefined
Answer the question
In order to leave comments, you need to log in
Did it like this:
var jsonBody = JSON.parse(responseBody);
console.log(jsonBody.data)
var jsonData = JSON.parse(jsonBody.data)
console.log(jsonData.userId)
pm.test("userId from env is equal to userId from response", function () {
pm.expect(parseInt(pm.environment.get("userId"))).to.equal(
jsonData.userId
);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question