1

I get an error when trying to extract a value from a JSON response body in Postman.

ReferenceError: teste is not defined

This is what I have tried:

  var jsonData = JSON.parse(responseBody);
  pm.globals.set("access_token",jsonData.access_token)

  ** pm.globals.set("x-teste-msg-sign",jsonData.x-teste-msg-sign)
0

1 Answer 1

1

It's more than likely to be this, judging by the way you're extracting the access_token

  pm.globals.set("x-teste-msg-sign", jsonData["x-teste-msg-sign"])

As the key contains the - character, you would need to use bracket notion rather than dot notion to access the value.

Here's an example:

let jsonData = {
  "x-teste-msg-sign": 12345
}

console.log(jsonData.x-teste-msg-sign) // This would cause a script error
console.log(jsonData["x-teste-msg-sign"]) // This would set the value to the variable
Sign up to request clarification or add additional context in comments.

2 Comments

It worked .Thank very much . it was very difficult to find, I searched a lot
It's a common problem for people accessing different part of a JSON response. Could you accept this as the answer please 😁

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.