# Verify the first Json response Object values are present in second Json Response Object values

**URL:** <https://community.postman.com/t/verify-the-first-json-response-object-values-are-present-in-second-json-response-object-values/20142>\
**Category:** Help Hub\
**Tags:** variables, responseassertion, json, tests, collections\
**Created:** [February 7, 2021, 7:43pm UTC](https://community.postman.com/t/verify-the-first-json-response-object-values-are-present-in-second-json-response-object-values/20142 "2021-02-07T19:43:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bhasker.vade](https://avatars.discourse-cdn.com/v4/letter/b/f9ae1b/32.png) [@bhasker.vade](https://community.postman.com/u/bhasker.vade)\
**Post date:** [February 7, 2021, 7:43pm UTC](https://community.postman.com/t/verify-the-first-json-response-object-values-are-present-in-second-json-response-object-values/20142/1 "2021-02-07T19:43:25Z")

</div>

Hello Team ,

can someone please help me here

I have 2 Json Reponses , I need to verify that first objects value are present in Second objects values

first object name and second object name are different

**in first response I have 977 objects same name below is example**

{

```
"name": "i_vestmark_tpi_household_allocations",

"elements": [

    {

        "household_name": "Test Household DEF"

    },

    {

        "household_name": "test"

    },

    {

        "household_name": "Test Household 3"

    },

    {

        "household_name": "Test WM"

    },

    {

        "household_name": "Test HH Sandeep"

    },

    {

        "household_name": "Test Co-Relationship Household"

    },

    {

        "household_name": "Test Sandy 1"

    },

```

**In 2 nd Response I have 4000 objects**

{

```
"name": "i_source_data_salesforce_tpi_target_allo_v2",

"elements": [

    {

        "householdname": "Test Household DEF",

        "organization": "TPI"

    },

    {

        "householdname": "test",

        "organization": "TPI"

    },

    {

        "householdname": "Test Household 3",

        "organization": "TPI"

    },

    {

        "householdname": "Test WM",

        "organization": "TPI"

    },

    {

        "householdname": "Test HH Sandeep",

        "organization": "TPI"

    },

    {

        "householdname": "Test Co-Relationship Household",

        "organization": "TPI"

    },

    {

        "householdname": "Test Sandy 1",

        "organization": "TPI"

    },

    {

        "householdname": "Test HHs",

        "organization": "TPI"

    },

    {

        "householdname": "Lee, Jeffrey Household",

        "organization": "TPI"

    },

    {

        "householdname": "D'Alessandro, Gail Household",

        "organization": "TPI"

    },

    {

        "householdname": "Lee, Michelle Household",

        "organization": "TPI"

    },

    {

        "householdname": "Lee, Andrew Household",

        "organization": "TPI"

    },

    {

        "householdname": "ZZX-Lee, Christopher Household",

        "organization": "TPI"

    },

    {

        "householdname": "Lee, Christopher Household",

        "organization": "TPI"

    },

    {

        "householdname": "McCarthy, Kate & Bryan Household",

        "organization": "TPI"

    },

    {

        "householdname": "Richards, Rob Household",

        "organization": "TPI"

    },

    {

        "householdname": "DiOrio, Chris & Veronica Household",

        "organization": "TPI"

    },

    {

        "householdname": "ZZX-Sagalyn, Rita",

        "organization": "TPI"

    },

    {

        "householdname": "Sawhney-Martin, Shilpa & James Household",

        "organization": "TPI"

    },

    {

        "householdname": "Dvorstov, Mikhail & Elena Household",

        "organization": "TPI"

    },

    {

        "householdname": "Percy, Jane Household",

        "organization": "TPI"

    },

    {

        "householdname": "Joel, Michael Household",

        "organization": "TPI"

    },

    {

        "householdname": "ZZ-TEST",

        "organization": "TPI"

    },

```

Here I need to verify that **household\_name** values from first response are present in Second **householdname** values .

I have tried it with for loop , can we do other way simple with assertions?

**I have written below like in in my First Request Test TAB**

let jsonData = pm.response.json().elements

pm.test(“success household\_name column stored as variable”, function () {

jsonData.forEach((item, index) =\> {

pm.collectionVariables.set(`one-${index}`, item[“household\_name”])

})

});

let DataSize = pm.response.json().elements.length

pm.environment.set(“Size”,DataSize);

**I have written below like in my Second Request Test TAB**  
et jsonData = pm.response.json().elements

var secondValue = ;

jsonData.forEach((item, index) =\> {

```
secondValue.push(item["householdname"]);

```

});

pm.test("Succes compared vestmark view household\_name values are present in salesforce view householdname organization = TPI ", function () {

for (var i = 0, len =pm.environment.get(‘Size’); i \< len; i++){

```
if(pm.expect(secondValue).to.include(pm.collectionVariables.get(`one-${i}`)));

```

}

});

can we do it any other simple way ?

---

<div class="post-metadata">

**Author:** ![payload-geoscientist](https://avatars.discourse-cdn.com/v4/letter/p/c2a13f/32.png) [@payload-geoscientist](https://community.postman.com/u/payload-geoscientist)\
**Post date:** [February 7, 2021, 9:11pm UTC](https://community.postman.com/t/verify-the-first-json-response-object-values-are-present-in-second-json-response-object-values/20142/2 "2021-02-07T21:11:03Z")

</div>

var initial\_resp = {  
“name”: “i\_vestmark\_tpi\_household\_allocations”,  
“elements”: [  
{  
“household\_name”: “Test Household DEF”  
},  
{  
“household\_name”: “test”  
},  
{  
“household\_name”: “Test Household 3”  
},  
{  
“household\_name”: “Test WM”  
},  
{  
“household\_name”: “Testqwewq WM”  
}]

}

var later\_response = {  
“name”: “i\_source\_data\_salesforce\_tpi\_target\_allo\_v2”,  
“elements”: [  
{  
“householdname”: “Test Household DEF”,  
“organization”: “TPI”  
},  
{  
“householdname”: “test”,  
“organization”: “TPI”  
},  
{  
“householdname”: “Test Household 3”,  
“organization”: “TPI”  
},  
{  
“householdname”: “Test WM”,  
“organization”: “TPI”  
}]

}

var household\_name\_array= initial\_resp.elements.map(function (element) { return element.household\_name; });

var var householdname\_array= later\_response .elements.map(function (element) { return element.householdname; });

var check = false;

var check = init\_map.every((el) =\> {  
return response\_map.indexOf(el) !== -1;  
});

//check will be true if later response has all the values from initial response

---

<div class="post-metadata">

**Author:** ![payload-geoscientist](https://avatars.discourse-cdn.com/v4/letter/p/c2a13f/32.png) [@payload-geoscientist](https://community.postman.com/u/payload-geoscientist)\
**Post date:** [February 7, 2021, 9:12pm UTC](https://community.postman.com/t/verify-the-first-json-response-object-values-are-present-in-second-json-response-object-values/20142/3 "2021-02-07T21:12:34Z")

</div>

Hope this works for you.

```auto
var later_response = {
    "name": "i_source_data_salesforce_tpi_target_allo_v2",
    "elements": [
        {
            "householdname": "Test Household DEF",
            "organization": "TPI"
        },
        {
            "householdname": "test",
            "organization": "TPI"
        },
        {
            "householdname": "Test Household 3",
            "organization": "TPI"
        },
        {
            "householdname": "Test WM",
            "organization": "TPI"
        }]
        
}

var initial_resp = {
    "name": "i_vestmark_tpi_household_allocations",
    "elements": [
        {
            "household_name": "Test Household DEF"
        },
        {
            "household_name": "test"
        },
        {
            "household_name": "Test Household 3"
        },
        {
            "household_name": "Test WM"
        }
}

```

```auto
var household_name_array= initial_resp.elements.map(function (element) { return element.household_name; });

var householdname_array= later_response .elements.map(function (element) { return element.householdname; });

var check = false;

var check = household_name_array.every((el) => {
	return householdname_array.indexOf(el) !== -1;
});

//check will be true if later response has all the values from initial response

```

---

<div class="post-metadata">

**Author:** ![bhasker.vade](https://avatars.discourse-cdn.com/v4/letter/b/f9ae1b/32.png) [@bhasker.vade](https://community.postman.com/u/bhasker.vade)\
**Post date:** [February 8, 2021, 9:06pm UTC](https://community.postman.com/t/verify-the-first-json-response-object-values-are-present-in-second-json-response-object-values/20142/4 "2021-02-08T21:06:29Z")

</div>

Got it thanks…

---

<div class="post-metadata">

**Author:** ![bhasker.vade](https://avatars.discourse-cdn.com/v4/letter/b/f9ae1b/32.png) [@bhasker.vade](https://community.postman.com/u/bhasker.vade)\
**Post date:** [February 8, 2021, 9:07pm UTC](https://community.postman.com/t/verify-the-first-json-response-object-values-are-present-in-second-json-response-object-values/20142/5 "2021-02-08T21:07:27Z")

</div>

I have used like below

**First TAB**  
// store vestmark list in variable

let jsonData = pm.response.json().elements

var household\_name\_array = ;

pm.test(“success household\_name column stored as variable vestmarkList”, function () {

household\_name\_array= jsonData.map(function (elements) { return elements.household\_name; });

pm.collectionVariables.set(`vestmarkList`, JSON.stringify(household\_name\_array));

});

**Second TAB**

// Validate Vestmark values are in Salesforce table

let jsonData = pm.response.json().elements;

var vestMarkList = JSON.parse(pm.collectionVariables.get(`vestmarkList`));

var salesforceList = jsonData.map(function (element) {return element.householdname});

var check = false;

pm.test("Succes compared vestmark view household\_name values are present in salesforce view householdname organization = TPI ", function () {

```
check = vestMarkList.forEach((el) => {

    return salesforceList.indexOf(el) !== -1;

            

})

```

});
