1

i am working on test unit in postman ( test script )

the request body is :

{
"sessionKey": {{varsessionKey}},
"project_id": {{varproject_id}}
}

so i gave them data from json file

and in test script :

console.log(JSON.parse(pm.request.body.raw));

gave me error

valid data type | JSONError: No value found for key sessionKey at 2:16 "sessionKey": somesessionKey, ^ POST

although the result of :

console.log(pm.request.body.raw);

"{ "sessionKey": somesessionKey, "project_id": 1}"

and also if the request have static value not like {{var}} the json parse will work correctly

so my problem is that i cant access the variable inside the object like :

var req = JSON.parse(pm.request.body.raw);
console.log(req.project_id);

any help is highly appreciated

Abd Al Rahman
  • 121
  • 2
  • 9

0 Answers0