2

I have a problem trying to check a JSON value in the response body using POSTMAN because the JSON object name has a full-stop in it

Usually a JSON response body would be something like this:

{
"restapi": "Beta",
"logLevel": "INFO"
}

So normally we can do a test on the JSON value like this using POSTMAN:

pm.test("Your test name", function () {
    var jsonData = pm.response.json();
    pm.expect(jsonData.restapi).to.eql(Beta);
});

But the problem I'm having now is that the JSON object name has a full stop like this

{
    "restapi.name": "Beta",
    "logLevel.sleep": "INFO"
}

So if I try to do read the object like this, it will come out with an error

pm.test("Your test name", function () {
    var jsonData = pm.response.json();
    pm.expect(jsonData.restapi.name).to.eql(Beta);
});

2 Answers2

1

You can just reference the key value by using brackets around the name:

jsonData["restapi.name"]

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

object properties can be accessed with . operator or with associative array indexing using []. ie. object.property is equivalent to object["property"]

this should do the trick

jsonData["restapi.name"]
MartenCatcher
  • 2,713
  • 8
  • 26
  • 39