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

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 ?

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

Hope this works for you.

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"
        }
}
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
1 Like

Got it thanks…

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;

            

})

});