My goal is to set environment variable from responseBody so I could reuse it later on in other requests. Before I do that I want to first fetch that variable, however I encounter issues.
So my responseBody looks like:
{
"email":"test_email",
"tokens":"{'refresh': 'sample_refresh', 'access': 'sample access'}"
}
Note that tokens are passed as string. Here is the code in postman tests section:
response = JSON.parse(responseBody);
tokens = response.tokens
accesstry1 = tokens["access"]
accesstry2 = tokens[1]
console.log(tokens)
Result: "{'refresh': 'sample_refresh', 'access': 'sample access'}"
console.log(accesstry1)
Result: undefined
console.log(accesstry2)
Result: "'"
I also tried to parse tokens variable but it gave me an error:
tokens = response.tokens
tokens_parsed = JSON.parse(tokens)
Result JSONError: Unexpected token '\'' at 1:2 {'refresh':
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoicmVmcmVza