# How to exclude a dynamic value when testing response body with lodash \_.isEqual(jsonData,

**URL:** <https://community.postman.com/t/how-to-exclude-a-dynamic-value-when-testing-response-body-with-lodash-isequal-jsondata/11275>\
**Category:** Help Hub\
**Tags:** tests\
**Created:** [March 10, 2020, 1:19pm UTC](https://community.postman.com/t/how-to-exclude-a-dynamic-value-when-testing-response-body-with-lodash-isequal-jsondata/11275 "2020-03-10T13:19:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![IFS-QA](https://avatars.discourse-cdn.com/v4/letter/i/a8b319/32.png) [@IFS-QA](https://community.postman.com/u/IFS-QA)\
**Post date:** [March 10, 2020, 1:19pm UTC](https://community.postman.com/t/how-to-exclude-a-dynamic-value-when-testing-response-body-with-lodash-isequal-jsondata/11275/1 "2020-03-10T13:19:02Z")

</div>

We are developing API’s and I need the ability to verify the entire payload of certain response bodies with exception of a dynamic “generateDateTime”: “2020-03-09T16:24:50.58”, value. I’m using lodash test snippet below which works perfectly for static response bodies that have no dynamic values… But I need a solution for either verifying the static response body + the dynamic “generateDateTime”: or to somehow exclude the “generateDateTime”: value in the test assertion.

var jsonData = JSON.parse(responseBody);  
var \_ = require(‘lodash’);  
tests[“Correct Response Body is Returned”] = \_.isEqual(jsonData,

{

“My Response Body”

}  
});

Thanks!!!

---

<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:** [March 10, 2020, 7:28pm UTC](https://community.postman.com/t/how-to-exclude-a-dynamic-value-when-testing-response-body-with-lodash-isequal-jsondata/11275/2 "2020-03-10T19:28:24Z")

</div>

Hi Chris,

I just wanted to point out that the more modern way of writing tests in Postman is using the Chai.js assertion library. All code snippets support that now.

Since jsonData is a JavaScript object, I would simply remove the property generateDateTime from the response.

`delete jsonData.generateDateTime;`

---

<div class="post-metadata">

**Author:** ![IFS-QA](https://avatars.discourse-cdn.com/v4/letter/i/a8b319/32.png) [@IFS-QA](https://community.postman.com/u/IFS-QA)\
**Post date:** [March 10, 2020, 8:50pm UTC](https://community.postman.com/t/how-to-exclude-a-dynamic-value-when-testing-response-body-with-lodash-isequal-jsondata/11275/3 "2020-03-10T20:50:46Z")

</div>

Thank you for the reply! Just for clarification your saying that I should be using the Chai assertions as opposed to lodash? I apologize I’m a bit of a newbie to Postman can you be specific about how and where to use the delete jsonData.generateDateTime; within the lodash test assertion I provided?

---

<div class="post-metadata">

**Author:** ![IFS-QA](https://avatars.discourse-cdn.com/v4/letter/i/a8b319/32.png) [@IFS-QA](https://community.postman.com/u/IFS-QA)\
**Post date:** [March 11, 2020, 5:48pm UTC](https://community.postman.com/t/how-to-exclude-a-dynamic-value-when-testing-response-body-with-lodash-isequal-jsondata/11275/4 "2020-03-11T17:48:38Z")

</div>

OK after some trail and error I this is what worked: Thanks again!! I’ve been doing some reading on Chai “expect” I think it will work well too.

var jsonData = JSON.parse(responseBody);  
delete jsonData.generationDateTime;  
var \_ = require(‘lodash’);  
tests[“All Correct JSON is Displayed”] = \_.isEqual(jsonData,

{  
“srFoo”: 5201,  
“srFooName”: “Transaaction”,  
“pageId”: 5204,  
“pageName”: “Entry”,  
**"generationDateTime": “2020-03-11T11:29:47.893”,\*\*\*\*(Removed property)**  
“modifiedDate”: “2019-03-15T14:43:38.763”,  
“pageButtons”: [  
{  
“name”: “Next”,  
“text”: “Next”,  
“isDefault”: true,

---

<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:** [March 15, 2020, 2:57am UTC](https://community.postman.com/t/how-to-exclude-a-dynamic-value-when-testing-response-body-with-lodash-isequal-jsondata/11275/5 "2020-03-15T02:57:03Z")

</div>

You don’t really need lodash, if you ask me.

I would write the test like this:

```
pm.test("Correct Response Body is Returned", () => {
    const expectedResponse = { "foo": "bar"};
    const response = pm.response.json();
    delete response.generateDateTime;
    pm.expect(response).to.eql(expectedResponse);
});
```

---

<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:** [March 15, 2020, 7:55am UTC](https://community.postman.com/t/how-to-exclude-a-dynamic-value-when-testing-response-body-with-lodash-isequal-jsondata/11275/6 "2020-03-15T07:55:27Z")

</div>

I agree with @vdespa here, for me Lodash isn’t needed and the newer `pm.test` function makes things more readable, in my opinion. 😁

Also, for most Lodash functions like `isEqual` you don’t need to use a _require_ statement to bring them into the sandbox environment. So if you removed the `var _ = require(‘lodash’);` from your code, it would still work. 😁
