jsontestingpostmanpostman-testcase

How to read a JSON object with a full-stop in the name using POSTMAN?


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);
});

Solution

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

    jsonData["restapi.name"]