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:
Hi.
I am doing my first steps towards an “advanced” use of Postman. I am trying to extract data from a JSON response. The JSON response looks like:
{
"args": {},
"headers": {
"x-forwarded-proto": "https",
"host": "postman-echo.com",
"accept": "*/*",
"accept-encoding": "gzip, deflate",
"cache-control": "no-cache",
"cookie": "sails.sid=s%3AgX-JxoOgGc7tWEb8jw_6YBH5VKcxH8R8.M7J38uMcN090VYnxRHu6eF4rkq7arAemQXhfRd9TWz4",
"postman-token"…
@sunilammanabrolu
You want to use the bracket notation to find that “ldap-servers” in your scenario.
You can read about the two methods here:
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
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