# Response API comparison - Selective elimination of nodes before doing the compare

**URL:** <https://community.postman.com/t/response-api-comparison-selective-elimination-of-nodes-before-doing-the-compare/8298>\
**Category:** Help Hub\
**Created:** [October 10, 2019, 3:37pm UTC](https://community.postman.com/t/response-api-comparison-selective-elimination-of-nodes-before-doing-the-compare/8298 "2019-10-10T15:37:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![perinbaraj](https://avatars.discourse-cdn.com/v4/letter/p/bc8723/32.png) [@perinbaraj](https://community.postman.com/u/perinbaraj)\
**Post date:** [October 10, 2019, 3:37pm UTC](https://community.postman.com/t/response-api-comparison-selective-elimination-of-nodes-before-doing-the-compare/8298/1 "2019-10-10T15:37:01Z")

</div>

I’m running a test to compare expected json response with actual json response from the application. As part of the test, I want to remove a node whose values are dynamic. During each iteration, the dynamic content will change and will fail the json compare. I would like to know if we have any method which we can use to do selective comparison.

Below script, compare validates the entire json. But need a method to remove a few of the dynamic nodes before doing the compare.

```
var accounts = data.accounts;
var expJSON = data.expectedresponse;

//JSON Compare step
pm.test("jsonCompare", function () {
    var jsonData = pm.response.json();
    pm.expect(jsonData).to.eql(expJSON);
});

```

I can use below approach for testing Block by block, but having 1000’s of nodes to compare, the below approach is not practical.

```
tests["Validate Question 1"] = jsonData.questions[0].title === "adckddkd";
tests["Validate Question 2"] = jsonData.questions[1].title === " *******";
```

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [October 10, 2019, 5:05pm UTC](https://community.postman.com/t/response-api-comparison-selective-elimination-of-nodes-before-doing-the-compare/8298/2 "2019-10-10T17:05:47Z")

</div>

Hey @perinbaraj,

Welcome to the community!! 🌟

Are you able to provide a sample of the 2 different responses that you’re likely to receive?

Just so that people can _see_ which parts of the data are going to be changing.

---

<div class="post-metadata">

**Author:** ![perinbaraj](https://avatars.discourse-cdn.com/v4/letter/p/bc8723/32.png) [@perinbaraj](https://community.postman.com/u/perinbaraj)\
**Post date:** [October 10, 2019, 8:39pm UTC](https://community.postman.com/t/response-api-comparison-selective-elimination-of-nodes-before-doing-the-compare/8298/3 "2019-10-10T20:39:50Z")

</div>

Hi Danny,  
Thank you for the response.  
Sample:  
Data 1:  
{  
“id”: “abcd4234232242”,  
“Example1”: “this is a test”,  
“SessionId”: 2d3d3d34342323334,  
“questions”: [  
{  
“id”: “abcd4234232242"”,  
"  
}  
]  
}

Data 2:  
{  
“id”: “abcd4234232243”,  
“Example1”: “this is a test”,  
“SessionId”: 2d3d3d3434232335,  
“questions”: [  
{  
“id”: “abcd4234232243"”,  
"  
}  
]  
}  
Consider id and sessionid has dynamic values.

* * *

For now the solution i got from another forum:

function convertToObjectWithExcludeKeys(orginalObject, excludeKeys){  
var newObj = {};  
Object.keys(orginalObject).map(key =\> {  
if(excludeKeys.indexOf(key) \< 0){  
newObj[key] = orginalObject[key];  
}

```
})
return newObj;

```

}

var b = {Sample1}  
var a = {Sample2};

var excludeKeys = [“Value1”,“Value2”,“Value3”];

//Convert original objects to temporary objects with exclude keys  
var tmpA = convertToObjectWithExcludeKeys(a, excludeKeys);  
var tmpB = convertToObjectWithExcludeKeys(b, excludeKeys);

console.log(“tmpA”, tmpA);  
console.log(“tmpB”, tmpB);

pm.test(‘Equals’, function() {  
pm.expect(\_.isEqual(tmpA, tmpB)).to.be.true  
});
