# How to verify full body response within a Pre requisite script and compare with response body?

**URL:** <https://community.postman.com/t/how-to-verify-full-body-response-within-a-pre-requisite-script-and-compare-with-response-body/15123>\
**Category:** Help Hub\
**Tags:** tests\
**Created:** [August 18, 2020, 7:18pm UTC](https://community.postman.com/t/how-to-verify-full-body-response-within-a-pre-requisite-script-and-compare-with-response-body/15123 "2020-08-18T19:18:24Z")\
**Posts on this page:** 10\
**Page:** 2

<div class="post-metadata">

**Author:** ![shahbaz.shiekhqa](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@shahbaz.shiekhqa](https://community.postman.com/u/shahbaz.shiekhqa)\
**Post date:** [September 10, 2020, 10:14pm UTC](https://community.postman.com/t/how-to-verify-full-body-response-within-a-pre-requisite-script-and-compare-with-response-body/15123/21 "2020-09-10T22:14:44Z")

</div>

Thank you for your help Michael, really appreciate the effort , i have not tested it yet … but am sure it should work … ill get back momentarily

---

<div class="post-metadata">

**Author:** ![shahbaz.shiekhqa](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@shahbaz.shiekhqa](https://community.postman.com/u/shahbaz.shiekhqa)\
**Post date:** [September 18, 2020, 2:10pm UTC](https://community.postman.com/t/how-to-verify-full-body-response-within-a-pre-requisite-script-and-compare-with-response-body/15123/22 "2020-09-18T14:10:33Z")

</div>

Hi Allen,

how would you write that in the tests tab?  
if i have something like this --\>  
[

```
{

    "sectionId": 1,

    "sectionTitle": "Setup for Program Adminstrators",

    "enabled": true,

    "sortOrder": 1,

    "contents": [

        {

            "contentId": 1,

            "sectionId": 1,

            "contentTitle": "User Roles",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 1

        },

        {

            "contentId": 2,

            "sectionId": 1,

            "contentTitle": "Create New User",

            "pdfLink": "PDF",

            "videoLink": "Video",

            "sortOrder": 2

        },

        {

            "contentId": 3,

            "sectionId": 1,

            "contentTitle": "Create Self-Registration Code",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 3

        },

        {

```

do i just copy the whole response and add it to the test tabs…?

---

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [September 18, 2020, 3:30pm UTC](https://community.postman.com/t/how-to-verify-full-body-response-within-a-pre-requisite-script-and-compare-with-response-body/15123/23 "2020-09-18T15:30:03Z")

</div>

I’d do it like this:

```auto
const jsonData = pm.response.json();
const lastResponse = pm.collectionVariables.get('lastResponse');
if(lastResponse) {
  lastResponse = JSON.parse(lastResponse);
  pm.test('response is the same as last time', function(){
    pm.expect(jsonData).to.eql(lastResponse);
  });
}

pm.collectionVariables.set('lastResponse', jsonData);

```

---

<div class="post-metadata">

**Author:** ![shahbaz.shiekhqa](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@shahbaz.shiekhqa](https://community.postman.com/u/shahbaz.shiekhqa)\
**Post date:** [September 18, 2020, 7:59pm UTC](https://community.postman.com/t/how-to-verify-full-body-response-within-a-pre-requisite-script-and-compare-with-response-body/15123/24 "2020-09-18T19:59:08Z")

</div>

Hi I did try that

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/9/b/9b3c4954ba7614a11a3718fd793bcc83ac6d294a.png)

I am getting an error…

should i copy over the current full body in the test tab so it has something to test against ?

---

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [September 18, 2020, 8:12pm UTC](https://community.postman.com/t/how-to-verify-full-body-response-within-a-pre-requisite-script-and-compare-with-response-body/15123/25 "2020-09-18T20:12:18Z")

</div>

I forgot to add in the script we’d need to stringify the response object.

```auto
const jsonData = pm.response.json();
const lastResponse = pm.collectionVariables.get('lastResponse');
if(lastResponse) {
  lastResponse = JSON.parse(lastResponse);
  pm.test('response is the same as last time', function(){
    pm.expect(jsonData).to.eql(lastResponse);
  });
}

pm.collectionVariables.set('lastResponse', JSON.stringify(jsonData));

```

---

<div class="post-metadata">

**Author:** ![shahbaz.shiekhqa](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@shahbaz.shiekhqa](https://community.postman.com/u/shahbaz.shiekhqa)\
**Post date:** [September 18, 2020, 8:31pm UTC](https://community.postman.com/t/how-to-verify-full-body-response-within-a-pre-requisite-script-and-compare-with-response-body/15123/26 "2020-09-18T20:31:54Z")

</div>

I tried that i am getting an error , but my question is what if i put the whole body response in the test tab… like so :  
pm.test(“Your test name”, function () {

```
var jsonData = pm.response.json();

pm.expect(jsonData.value).to.eql([

{

    "sectionId": 1,

    "sectionTitle": "Setup for Program Adminstrators",

    "enabled": true,

    "sortOrder": 1,

    "contents": [

        {

            "contentId": 1,

            "sectionId": 1,

            "contentTitle": "User Roles",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 1

        },

        {

            "contentId": 2,

            "sectionId": 1,

            "contentTitle": "Create New User",

            "pdfLink": "PDF",

            "videoLink": "Video",

            "sortOrder": 2

        },

        {

            "contentId": 3,

            "sectionId": 1,

            "contentTitle": "Create Self-Registration Code",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 3

        },

        {

            "contentId": 4,

            "sectionId": 1,

            "contentTitle": "User Management",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 4

        },

        {

            "contentId": 5,

            "sectionId": 1,

            "contentTitle": "Email Settings",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 5

        },

        {

            "contentId": 6,

            "sectionId": 1,

            "contentTitle": "Download RFIs",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 6

        },

        {

            "contentId": 7,

            "sectionId": 1,

            "contentTitle": "Manage Departments & Setup Hierarchies",

            "pdfLink": "PDF",

            "videoLink": "Video",

            "sortOrder": 7

        },

        {

            "contentId": 8,

            "sectionId": 1,

            "contentTitle": "Tracer Category Setup",

            "pdfLink": "PDF",

            "videoLink": "Video",

            "sortOrder": 8

        },

        {

            "contentId": 9,

            "sectionId": 1,

            "contentTitle": "Guest Access Setup",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 9

        }

    ]

},

{

    "sectionId": 2,

    "sectionTitle": "Standards for Program Adminstrators",

    "enabled": true,

    "sortOrder": 2,

    "contents": [

        {

            "contentId": 10,

            "sectionId": 2,

            "contentTitle": "User Guilde",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 1

        },

        {

            "contentId": 11,

            "sectionId": 2,

            "contentTitle": "User Roles",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 2

        },

        {

            "contentId": 12,

            "sectionId": 2,

            "contentTitle": "Filters & Service Profiles",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 3

        },

        {

            "contentId": 13,

            "sectionId": 2,

            "contentTitle": "Home Page Overview",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 4

        },

        {

            "contentId": 14,

            "sectionId": 2,

            "contentTitle": "Navigate and Score the EPs",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 5

        },

        {

            "contentId": 15,

            "sectionId": 2,

            "contentTitle": "Organization Documentation",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 6

        },

        {

            "contentId": 16,

            "sectionId": 2,

            "contentTitle": "Plan of Action Tips",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 7

        },

        {

            "contentId": 17,

            "sectionId": 2,

            "contentTitle": "Create Scoring Assignments",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 8

        },

        {

            "contentId": 18,

            "sectionId": 2,

            "contentTitle": "Re-assign EPs",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 9

        },

        {

            "contentId": 19,

            "sectionId": 2,

            "contentTitle": "Bulk Scoring & Bulk Plan of Action",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 10

        },

        {

            "contentId": 20,

            "sectionId": 2,

            "contentTitle": "Cross Program Scoring",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 11

        },

        {

            "contentId": 21,

            "sectionId": 2,

            "contentTitle": "Create & Manage Tasks",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 12

        },

        {

            "contentId": 22,

            "sectionId": 2,

            "contentTitle": "Data Migration Reset",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 13

        },

        {

            "contentId": 23,

            "sectionId": 2,

            "contentTitle": "Upload and Submit FSA",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 14

        },

        {

            "contentId": 24,

            "sectionId": 2,

            "contentTitle": "FSA Submission Options",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 15

        },

        {

            "contentId": 25,

            "sectionId": 2,

            "contentTitle": "Email Communication",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 16

        },

        {

            "contentId": 26,

            "sectionId": 2,

            "contentTitle": "Presonal Profile Management",

            "pdfLink": "PDF",

            "videoLink": "Video",

            "sortOrder": 17

        },

        {

            "contentId": 27,

            "sectionId": 2,

            "contentTitle": "Reset Password Instructions",

            "pdfLink": "PDF",

            "videoLink": "Video",

            "sortOrder": 18

        }

    ]

}

```

]);

});

and then lets if i run it next week, it should have the same result, if its different than theres an issue …  
i did notice this is what i am getting if i click send:

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/f/c/fc432176301163986da841f110664e8de1f617db.png)

---

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [September 18, 2020, 9:08pm UTC](https://community.postman.com/t/how-to-verify-full-body-response-within-a-pre-requisite-script-and-compare-with-response-body/15123/27 "2020-09-18T21:08:55Z")

</div>

You can do it that way, but it’s effectively the same as setting it to a variable. Plus doing it this way means you have to continuously maintain the test.

You’re getting an error in your test because jsonData.value doesn’t exist in your response. try removing `.value`

---

<div class="post-metadata">

**Author:** ![shahbaz.shiekhqa](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@shahbaz.shiekhqa](https://community.postman.com/u/shahbaz.shiekhqa)\
**Post date:** [September 18, 2020, 9:13pm UTC](https://community.postman.com/t/how-to-verify-full-body-response-within-a-pre-requisite-script-and-compare-with-response-body/15123/28 "2020-09-18T21:13:34Z")

</div>

How do you know these things ? Awesome worked …🙂

so this solution is basically grabbing all the data and comparing real time test tab to the current body,  
(Also if lets say sectionid:1 is actually sectionid:2, then how would i debug that  
in the console?

looking at your code of “last response” how does PM know what last response is?

---

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [September 18, 2020, 9:43pm UTC](https://community.postman.com/t/how-to-verify-full-body-response-within-a-pre-requisite-script-and-compare-with-response-body/15123/29 "2020-09-18T21:43:54Z")

</div>

You showed me the response, I saw there was no `value` property 🙂

I haven’t tried this, but you might be able to use the code [from here](https://gist.github.com/Yimiprod/7ee176597fef230d1451) to do a diff and print to the console.

---

<div class="post-metadata">

**Author:** ![shahbaz.shiekhqa](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@shahbaz.shiekhqa](https://community.postman.com/u/shahbaz.shiekhqa)\
**Post date:** [October 1, 2020, 4:59pm UTC](https://community.postman.com/t/how-to-verify-full-body-response-within-a-pre-requisite-script-and-compare-with-response-body/15123/30 "2020-10-01T16:59:44Z")

</div>

Hi I have another question please if you could help

> [@How to add full Post Raw Body within a Collection Variable to use in the next api call?](https://community.postman.com/t/how-to-add-full-post-raw-body-within-a-collection-variable-to-use-in-the-next-api-call/16361):
>
> How to add full Post Raw Body within a Collection Variable to use in the next api call? I have the POST body parameters: { "announcementId": 0, "header": "Delete Testing slide through API - Header - SS -Time Lapsed should not display", "body": "Delete Testing slide through API - Body - SS Time Lapsed should not display", "announcementType": 0, "imageUrl": "", "updateDate": "2020-09-22T23:24:10.382Z", "isAlertBanner": true, "startDate": "2020-08-29T02:21:22.382Z", "endDate": "2020-09-…

[Previous page](https://community.postman.com/t/how-to-verify-full-body-response-within-a-pre-requisite-script-and-compare-with-response-body/15123.md?page=1)
