Search code examples
postmanweb-api-testingpostman-testcase

How can I validate JSON array value in postman?


{
    "success": {
        "text": "successfully! deleted Records"
    }
}

Want to validate text value is "successfully! deleted Records"

I tried with this

pm.test("Your test name", function () {
    var jsonData = pm.response.json();

    pm.expect(jsonData[0].text).to.eql("successfully! deleted Records");
});

Solution

  • You're trying to retrieve data from a JSON object, not from an array. Hence, it should be as follows.

    pm.test("Your test name", function () {
        var jsonData = pm.response.json();    
        pm.expect(jsonData.success.text).to.eql("successfully! deleted Records");
    });