1

I need to validate the value of "@type" attribute in the below response through POSTMAN JS tests.but when am trying to write tests am getting a syntax error(Invalid or unexpected token)

JS Test line:

var jsonData = JSON.parse(responseBody);
console.log(jsonData.ErrorResponse.Result.Error[0].@type)

Response:

{
    "ErrorResponse": {
        "Result": {
            "Error": [
                {
                    "@type": "ErrorDetail",
                    "StatusCode": "400",                    
                }
            ]
        }
    }
}

1 Answers1

0

You need to use bracket notation ["@type"] to access that value:

var jsonData = pm.response.json();

console.log(jsonData.ErrorResponse.Result.Error[0]['@type'])

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors

Danny Dainton
  • 23,069
  • 6
  • 67
  • 80