# How to validate multiple different data from postman response

**URL:** <https://community.postman.com/t/how-to-validate-multiple-different-data-from-postman-response/38089>\
**Category:** Help Hub\
**Tags:** json-response\
**Created:** [August 10, 2022, 3:50pm UTC](https://community.postman.com/t/how-to-validate-multiple-different-data-from-postman-response/38089 "2022-08-10T15:50:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bharath4172](https://avatars.discourse-cdn.com/v4/letter/b/76d3ee/32.png) [@bharath4172](https://community.postman.com/u/bharath4172)\
**Post date:** [August 10, 2022, 3:50pm UTC](https://community.postman.com/t/how-to-validate-multiple-different-data-from-postman-response/38089/1 "2022-08-10T15:50:34Z")

</div>

Hi, Can some one help on my issue.  
I have multiple responses (Around 70) in single request. How to validate this when we have multiple responses. Below i have attached the Image. in that I have responses for stateProvinces.

 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/2/230dc2e2d86467be555583dbd1ebd9323b07808c.png)

---

<div class="post-metadata">

**Author:** ![w4dd325](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/w4dd325/32/12436_2.png) [@w4dd325](https://community.postman.com/u/w4dd325)\
**Post date:** [August 11, 2022, 9:36am UTC](https://community.postman.com/t/how-to-validate-multiple-different-data-from-postman-response/38089/2 "2022-08-11T09:36:02Z")

</div>

Hi @bharath4172

You are working inside an array so you would need to specify the index you are asserting.

```auto
const response = pm.response.json();

pm.test("Check stateDesc values", function () {
    pm.expect(response.stateDesc[0].countryName).to.eql("Michigan");
    pm.expect(response.stateDesc[1].countryName).to.eql("Idaho");
    pm.expect(response.stateDesc[2].countryName).to.eql("Colorado");
    pm.expect(response.stateDesc[3].countryName).to.eql("Utah");
});

```

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [January 16, 2023, 10:19am UTC](https://community.postman.com/t/how-to-validate-multiple-different-data-from-postman-response/38089/3 "2023-01-16T10:19:21Z")

</div>

Not sure why this post come to the top of the list as its over six months old.

However, purely from a testing perspective, I would not recommend asserting on 4 elements in one go like this.

If the first one fails, then the others will not run.

It breaks the singular rule.

These should be singular tests. It should be possible to create a loop to loop through the response, so it will run once for each element. That way, if more than one fails, it will show in the results.

This all depends on what you are trying to assert. You could use the JavaScript map function to save all of the stateCodes into a new array, and then just check if the state codes exist “pm.expect(array).to.include(countryName)”.

Please don’t use “pm.expect(array).to.have.members([‘Michigan’,‘Idaho’])” as that has the same issue in respect to testing more than one thing at at time.

You could also do a find to see if the element exists in the array. In this example, stateProvinces is an array, so you should be able to do this direct against that array and all you do then is assert that the response is not null or undefined.

---

<div class="post-metadata">

**Author:** ![w4dd325](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/w4dd325/32/12436_2.png) [@w4dd325](https://community.postman.com/u/w4dd325)\
**Post date:** [January 16, 2023, 6:30pm UTC](https://community.postman.com/t/how-to-validate-multiple-different-data-from-postman-response/38089/4 "2023-01-16T18:30:43Z")

</div>

Debatable, If the criteria you are testing against are that ALL should be as expected then if one item is missing/incorrect, you would want the test to fail.

Bare in mind that the example above was derived from the official Postman docs;

> **[Test script examples | Postman Learning Center](https://learning.postman.com/docs/writing-scripts/script-references/test-examples/#using-multiple-assertions)**
>
> Test script examples: documentation for Postman, the collaboration platform for API development. Create better APIs—faster.

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [January 17, 2023, 11:09am UTC](https://community.postman.com/t/how-to-validate-multiple-different-data-from-postman-response/38089/5 "2023-01-17T11:09:15Z")

</div>

Test approaches are debatable and best practice is always subjective.

But from experience, its best to have individual tests.

It doesn’t need to be a lot more code. Just define the expected results in an array, and then put your test in a loop. This way, all tests are executed, so your report will show you all of the potential defects instead of erroring on the first test and then not providing feedback on the other tests. You may have more than one bug, which is not being surfaced by the test.
