I would like to assert response body with JSON file in POSTMAN

I am new to postman and I would like to know how to assert request body from a JSON file which is the same file i pass the values/data in request body in multiple iterations using collection runner.

I wanted to verify whether the response body has same values which i have passed from the JSON file. I want to write a test script something like below where i can verify response has the values from iteration data of JSON file.

The above test script might absolutely incorrect. I just
I would appreciate it greatly if someone could help me with this assertion…

My JSON input file:

[
 {
   "POLCODE": "APOL500000",
   "EnrolmentSegmentValue": " ",
   "startDate": "2019-11-01",
   "stateValue": " ",
   "TIER": "TIER_1",
   
 },

Request Body:

{
	
	"policyEnrollmentList": [
		{
			
			"person": {
				"code": "{{personMEMCode_1}}",
				"name": "{{Name_1}}",
				"initials": "",
				"firstName": "{{firstName_1}}",
				"suffix": "",
				"middleName": "",
				"nameFormatCode": "SET_PER_NAM_FORMAT",
				"gender": "{{Gender_1}}",
				"dateOfBirth": "{{DOB_1}}",
				
}

Response Body:

{
    "saleDate": "2019-12-01",
    "calculateOnCancellation": false,
    "code": "APOL279906",
    "brandCode": " ",
    "lineOfBusinessCode": "HEALTH_INSURANCE",
    "rebateApplicant": [{
        "startDate": "2019-12-01",
        "declarationDate": "2019-12-01"
    }],
        "enrolmentSegment": [{
        "flexCodeDefinitionCode": "ENROLMENT_SEGMENTS",
        "startDate": "2019-12-01",
        "value": "ADF"
    }],
"policyEnrollmentList": [{
        "relationship": [{
            "flexCodeDefinitionCode": "RELATIONSHIPS",
            "startDate": "2019-11-01",
            "descriptor": "Policy Holder",
            "value": "MEMBR"
        }],
        "person": {
            "code": "MEM500000_1",
            "dateOfBirth": "1978-05-01",
            "dobInterpretation": "E",
            "emailAddress1": "LeonardHenrik@gmail2.com",
            "firstName": "Leonard",
            "gender": "M",
            "name": "Henrik",
           
}
1 Like

Let’s take just one value, POLCODE.

You can formulate your assertion like this:

const response = pm.response.json();
pm.expect(response.code).eql(pm.iterationData.get('POLCODE'));
1 Like