# Validate actual with expected array values

**URL:** <https://community.postman.com/t/validate-actual-with-expected-array-values/19394>\
**Category:** Help Hub\
**Created:** [January 21, 2021, 4:28pm UTC](https://community.postman.com/t/validate-actual-with-expected-array-values/19394 "2021-01-21T16:28:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jaggs\_jaggy75](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/jaggs_jaggy75/32/7044_2.png) [@Jaggs\_jaggy75](https://community.postman.com/u/Jaggs_jaggy75)\
**Post date:** [January 21, 2021, 4:28pm UTC](https://community.postman.com/t/validate-actual-with-expected-array-values/19394/1 "2021-01-21T16:28:35Z")

</div>

Hi,

Sorry but I searched the community but could not find a fix hence troubling the experts here.  
One of my API has a json response body as below:  
{  
“suggestions”: [  
{  
“value”: “jacket”  
},  
{  
“value”: “jacquard-knit socks”  
},  
{  
“value”: “jacquard-knit jumper”  
},  
{  
“value”: “jacquard-weave cotton rug”  
},  
{  
“value”: “jacquard-weave skirt”  
}  
]  
}

Now I need to validate each value of key “value:” with expected data set. should I create data set variables in Predefined script ? Not sure how this can be done, please suggect/help.

---

<div class="post-metadata">

**Author:** ![vdespa](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/vdespa/32/2770_2.png) [@vdespa](https://community.postman.com/u/vdespa)\
**Post date:** [January 23, 2021, 5:53pm UTC](https://community.postman.com/t/validate-actual-with-expected-array-values/19394/2 "2021-01-23T17:53:18Z")

</div>

I would do something like this:

```
const response = {
	"suggestions": [{
			"value": "jacket"
		},
		{
			"value": "jacquard - knit socks"
		}
	]
}

pm.test("has suggestions", () => {
    const suggestions = response.suggestions.map((item) => item.value);
    pm.expect(suggestions).to.have.members(["jacquard - knit socks", "jacket"]);
});
```

---

<div class="post-metadata">

**Author:** ![Jaggs\_jaggy75](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/jaggs_jaggy75/32/7044_2.png) [@Jaggs\_jaggy75](https://community.postman.com/u/Jaggs_jaggy75)\
**Post date:** [January 24, 2021, 8:30pm UTC](https://community.postman.com/t/validate-actual-with-expected-array-values/19394/3 "2021-01-24T20:30:55Z")

</div>

Thanks for the reply,

i used pm.test(“Body matches string”, function () {  
pm.expect(pm.response.text()).to.include(“jacket”,“jacket super skinny fit”,“jacket skinny fit”,“jacket slim fit”,“jacket with faux fur lining” );

To extend my test, how do I compare my response array with already defined data of array.  
For eg, send in jeans and get above. Would like to test with more data, how do I achieve that. please help.

---

<div class="post-metadata">

**Author:** ![vdespa](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/vdespa/32/2770_2.png) [@vdespa](https://community.postman.com/u/vdespa)\
**Post date:** [January 26, 2021, 5:11pm UTC](https://community.postman.com/t/validate-actual-with-expected-array-values/19394/4 "2021-01-26T17:11:23Z")

</div>

You need to consider that your test is weaker as it searching the entire response, with no regard to the underlying data structure.

---

<div class="post-metadata">

**Author:** ![Jaggs\_jaggy75](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/jaggs_jaggy75/32/7044_2.png) [@Jaggs\_jaggy75](https://community.postman.com/u/Jaggs_jaggy75)\
**Post date:** [January 28, 2021, 8:36am UTC](https://community.postman.com/t/validate-actual-with-expected-array-values/19394/5 "2021-01-28T08:36:50Z")

</div>

Dont really understand how my test is weak considering that I input a search and result is an array of values. I need to validate those values depending upon some predefined expected data.

Is there a way to create a mapping? or you suggest how to make my test realistic.
