AssertionError: expected undefined to deeply equal 'ville'

Hi,
i have a GET request which returns:

[
    {
        "idFacture": "d7b8a9b-64f0-45ae-964d-1a1e13ac878d",
        "nom": "Paul",
        "courriel": "paul@example.com",
        "types": [
            "ville",
            "pays",
            "nuage",
            "paradis",
            "espace",
            "mars",
            "univers"
        ]
    }
]

I want to add asertion for nom.
i tried this:

pm.test("Your test name", function () {
    var jsonData = JSON.parse(responseBody);
    pm.expect(jsonData.nom).to.eql("paul");
});

It returns:
AssertionError: expected undefined to deeply equal ‘paul’

Any help please.
Thank you

1 Like

@ps198478320 Hello :partying_face:

The error which you have faced is one of the common one we face when handling with JSON with arrays. So if you give it as

pm.test("Your test name", function () {
    var jsonData = JSON.parse(responseBody);
    pm.expect(jsonData[0].nom).to.eql("paul");
});

Please try this :blush:

For bigger response this tool might actually help you :raised_hands:

Please read my blog here which might help you with JSON parsing.

All the best! Please do let me know if you still face any issues here :wink:

2 Likes

Thank you so much @bpricilla