mardi 26 janvier 2021

How to validate array in json response?

Greatings,

I was wondering how to validate an array with postman

I have this answer:

{
"documents": [
            {
                "documentType": "FORM",
                "attributes": [
                    {
                        "kind": {
                            "code": "COMPANY",
                            "name": "Company name"
                        },
                        "value": "KKO",
                        "confidence": 0.0
                    },
                    {
                        "kind": {
                            "code": "AGREEMENT",
                            "name": "Agreement number"
                        },
                        "value": "123",
                        "confidence": 0.0
                    },
                    {
                        "kind": {
                            "code": "DATE_OF_ISSUE",
                            "name": "When it was created"
                        },
                        "value": "01/01/2019",
                        "confidence": 0.0
                    }
}

I want to validate the second attribute which is:

{
                        "kind": {
                            "code": "AGREEMENT",
                            "name": "Agreement number"
                        },

Including value field

                        "value": "123",
                        "confidence": 0.0
                    },

I was wondering what will be the easiest way to validate this?

I've tried to write paths like:

const response = pm.response.json()

attribute1 = response.data.documents[0];
attribute2 = response.data.documents[1];
attribute3 = response.data.documents[3];

pm.expect(attributes[1].kind.code).to.equal("AGREEMENT");

pm.expect(attributes[1].kind.name).to.equal("Agreement number");

but it is all too heavy and time consuming.

I would much appreciate if you share with me your experience and provide the clue on how to resolve my issue.

Thank you in advance

Aucun commentaire:

Enregistrer un commentaire