How to store a JSON in a variable and use it in the request body?

Hi @sonujain , Welcome to the community :partying_face:

you can try the below snippet:

    var jsonData = pm.response.json();

pm.environment.set("resp", JSON.stringify(jsonData));
   

//using forEach
_.forEach(jsonData, function(jsonData) {
    if(jsonData.return_code===0)
{
  pm.test('Result has expected properties', function(){
    pm.expect(jsonData).to.have.property('return_code');
    pm.expect(jsonData.return_code).to.eql(0);
  });
}

else if (jsonData.return_code !== 0)
{
        console.error(pm.environment.get('resp'));
}
});

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.