Fetch value of a key which has "-" in Tests

I have a json response as below
{

{

},
“status”: {
“ldap-servers”: [
{
“result”: “Connect_Success”,
“message”: “ldap connection check successful”,
“server”: {
“url”: “192.168.129.188:389”
}
},
{
“result”: “Connect_Failure”,
“message”: “LDAP Result Code 200 “Network Error”: dial tcp 192.168.129.188:386: connect: connection refused”,
“server”: {
“url”: “192.168.129.188:386”
}
}
]
}
}

I tried below in Tests and it gives an error
pm.test(“LDAP Connection test”, function () {
var jsonData = pm.response.json();
pm.expect(jsonData.status.ldap-servers[0].result).to.eql(“Connect_Success”);
});

LDAP Connection test | ReferenceError: servers is not defined

How do I escape the character “-” in pm.expect?

Postman version: 7.2.0

This is a duplicate question, you can find the answer here:

@sunilammanabrolu
You want to use the bracket notation to find that “ldap-servers” in your scenario.

You can read about the two methods here:
https://www.w3schools.com/js/js_json_objects.asp

And here’s an example of what your test might look like.

pm.test("LDAP Connection test", function () {
    pm.expect(jsonData.status["ldap-servers"][0].result).to.equal("Connect_Success");
});
1 Like