What parse and/or setEnvironmentVariable statement(s) must i use to get C2 from { "C1:C2"}?


May I get some help with using the proper parse and/or setEnvironmentVariable so that I can write a needed value to my environment variable?

I’m getting a response of

    "A": "B",
    "C": "D",
    "E": [
    "I1": "I2",
    "J1": "J2"

I’m thinking that my postman.setEnvironmentVariable(“F”, );

I’ve tried
var jsonData = JSON.parse(E[0].F1);
postman.setEnvironmentVariable(“serviceTypeId”, jsonData[1]);
but it’s not working.

I know that the var statement isn’t quite correct. What should it be? I probably don’t have the setEnvironmentVariable statement correct either.



The response body is available as the responseBody variable in the test scripts. In order to get the specific value, you can do something like this.

var jsonData = JSON.parse(responseBody);
postman.setEnvironmentVariable("serviceTypeId", jsonData[0].E[0]);

This should set the environment variable with the value F1:F2.

I hope this is what you are looking for.

1 Like

you rock, sir! Thank YOU.