# Need to verify multiple value pairs

**URL:** <https://community.postman.com/t/need-to-verify-multiple-value-pairs/40349>\
**Category:** Help Hub\
**Tags:** tests, collections, json\
**Created:** [October 22, 2022, 7:50pm UTC](https://community.postman.com/t/need-to-verify-multiple-value-pairs/40349 "2022-10-22T19:50:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![07se81](https://avatars.discourse-cdn.com/v4/letter/0/f08c70/32.png) [@07se81](https://community.postman.com/u/07se81)\
**Post date:** [October 22, 2022, 7:50pm UTC](https://community.postman.com/t/need-to-verify-multiple-value-pairs/40349/1 "2022-10-22T19:50:50Z")

</div>

_My question_: I want to verify that in year 2020 , the population was 326569308 in the first response below. how i can create the test for this with postman

_Details (like screenshots)_:

Json Response:

{  
“data”: [  
{  
“ID Nation”: “01000US”,  
“Nation”: “United States”,  
“ID Year”: 2020,  
“Year”: “2020”,  
“Population”: 326569308,  
“Slug Nation”: “united-states”  
},  
{  
“ID Nation”: “01000US”,  
“Nation”: “United States”,  
“ID Year”: 2019,  
“Year”: “2019”,  
“Population”: 324697795,  
“Slug Nation”: “united-states”  
},  
{  
“ID Nation”: “01000US”,  
“Nation”: “United States”,  
“ID Year”: 2018,  
“Year”: “2018”,  
“Population”: 322903030,  
“Slug Nation”: “united-states”  
},  
{  
“ID Nation”: “01000US”,  
“Nation”: “United States”,  
“ID Year”: 2017,  
“Year”: “2017”,  
“Population”: 321004407,  
“Slug Nation”: “united-states”  
},  
{  
“ID Nation”: “01000US”,  
“Nation”: “United States”,  
“ID Year”: 2016,  
“Year”: “2016”,  
“Population”: 318558162,  
“Slug Nation”: “united-states”  
},  
{  
“ID Nation”: “01000US”,  
“Nation”: “United States”,  
“ID Year”: 2015,  
“Year”: “2015”,  
“Population”: 316515021,  
“Slug Nation”: “united-states”  
},  
{  
“ID Nation”: “01000US”,  
“Nation”: “United States”,  
“ID Year”: 2014,  
“Year”: “2014”,  
“Population”: 314107084,  
“Slug Nation”: “united-states”  
},  
{  
“ID Nation”: “01000US”,  
“Nation”: “United States”,  
“ID Year”: 2013,  
“Year”: “2013”,  
“Population”: 311536594,  
“Slug Nation”: “united-states”  
}  
],  
“source”: [  
{  
“measures”: [  
“Population”  
],  
“annotations”: {  
“source\_name”: “Census Bureau”,  
“source\_description”: “The American Community Survey (ACS) is conducted by the US Census and sent to a portion of the population every year.”,  
“dataset\_name”: “ACS 5-year Estimate”,  
“dataset\_link”: “[American Community Survey (ACS)](http://www.census.gov/programs-surveys/acs/)”,  
“table\_id”: “B01003”,  
“topic”: “Diversity”,  
“subtopic”: “Demographics”  
},  
“name”: “acs\_yg\_total\_population\_5”,  
“substitutions”:   
}  
]  
}

_How I found the problem_:  
I am new to this and still learning

_I’ve already tried_:

i have tried this by  
var jsonData = pm.response.json();  
for (subArray of jsonData){  
for (subSubArray of subArray){  
if (subSubArray.data.Year == ‘2020’){  
pm.test(“population in 2020 was 326569308”, ()=\>{  
pm.expect(subSubArray.data.Population).to.eql(326569308)  
})  
}  
}  
but it is giving me an error TypeError: jsonData is not iterable

---

<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:** [October 23, 2022, 4:04pm UTC](https://community.postman.com/t/need-to-verify-multiple-value-pairs/40349/2 "2022-10-23T16:04:48Z")

</div>

Hi @07se81

Your response isn’t an array, the array is actually under “data”.

Try changing your first line to this;

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

---

<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:** [October 24, 2022, 12:59pm UTC](https://community.postman.com/t/need-to-verify-multiple-value-pairs/40349/3 "2022-10-24T12:59:11Z")

</div>

I use a helper function for searching JavaScript objects and returning an array of the results.

It’s so much easier to assert on.

```auto
var jsonData = {

"data": [
{
"ID Nation": "01000US",
"Nation": "United States",
"ID Year": 2020,
"Year": "2020",
"Population": 326569308,
"Slug Nation": "united-states"
},
{
"ID Nation": "01000US",
"Nation": "United States",
"ID Year": 2019,
"Year": "2019",
"Population": 324697795,
"Slug Nation": "united-states"
},
{
"ID Nation": "01000US",
"Nation": "United States",
"ID Year": 2018,
"Year": "2018",
"Population": 322903030,
"Slug Nation": "united-states"
},
{
"ID Nation": "01000US",
"Nation": "United States",
"ID Year": 2017,
"Year": "2017",
"Population": 321004407,
"Slug Nation": "united-states"
},
{
"ID Nation": "01000US",
"Nation": "United States",
"ID Year": 2016,
"Year": "2016",
"Population": 318558162,
"Slug Nation": "united-states"
},
{
"ID Nation": "01000US",
"Nation": "United States",
"ID Year": 2015,
"Year": "2015",
"Population": 316515021,
"Slug Nation": "united-states"
},
{
"ID Nation": "01000US",
"Nation": "United States",
"ID Year": 2014,
"Year": "2014",
"Population": 314107084,
"Slug Nation": "united-states"
},
{
"ID Nation": "01000US",
"Nation": "United States",
"ID Year": 2013,
"Year": "2013",
"Population": 311536594,
"Slug Nation": "united-states"
}
],
"source": [
{
"measures": [
"Population"
],
"annotations": {
"source_name": "Census Bureau",
"source_description": "The American Community Survey (ACS) is conducted by the US Census and sent to a portion of the population every year.",
"dataset_name": "ACS 5-year Estimate",
"dataset_link": "American Community Survey (ACS)",
"table_id": "B01003",
"topic": "Diversity",
"subtopic": "Demographics"
},
"name": "acs_yg_total_population_5",
"substitutions": ""
}
]
}

//return an array of objects according to key, value, or key and value matching
function getObjects(obj, key, val) {
    var objects = [];
    for (var i in obj) {
        if (!obj.hasOwnProperty(i)) continue;
        if (typeof obj[i] == 'object') {
            objects = objects.concat(getObjects(obj[i], key, val));    
        } else 
        //if key matches and value matches or if key matches and value is not passed (eliminating the case where key matches but passed value does not)
        if (i == key && obj[i] == val || i == key && val == '') { //
            objects.push(obj);
        } else if (obj[i] == val && key == ''){
            //only add if the object is not already in the array
            if (objects.lastIndexOf(obj) == -1){
                objects.push(obj);
            }
        }
    }
    return objects;
}

// creates array of the search results
var search = getObjects(jsonData,'ID Year','2020');

pm.test("Population in 2020 was 326569308", () => {
   pm.expect(search[0].Population).to.eql(326569308);
});

// or
var Population = getObjects(jsonData,'ID Year','2020')[0].Population;
console.log(Population);

pm.test("Population in 2020 was 326569308 V2", () => {
   pm.expect(Population).to.eql(326569308);
});

```
