# Need help in writting a test here

**URL:** <https://community.postman.com/t/need-help-in-writting-a-test-here/31257>\
**Category:** Help Hub\
**Created:** [January 5, 2022, 5:42am UTC](https://community.postman.com/t/need-help-in-writting-a-test-here/31257 "2022-01-05T05:42:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![swasthik08](https://avatars.discourse-cdn.com/v4/letter/s/dfb087/32.png) [@swasthik08](https://community.postman.com/u/swasthik08)\
**Post date:** [January 5, 2022, 5:42am UTC](https://community.postman.com/t/need-help-in-writting-a-test-here/31257/1 "2022-01-05T05:42:28Z")

</div>

I have a use case where I need to verify a key in an object based on another key in the same object,

```auto
{
"status": "success",
"version": "2.0",
"data": [
{
"key1": 4,
"key2": "100"
}, {
"key1": 2,
"key2": "200"
}
]
}

```

Here I want to assert key 1 = 4 /2 if key 2 is 100 /200

@danny-dainton Please help

---

<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:** [January 5, 2022, 2:27pm UTC](https://community.postman.com/t/need-help-in-writting-a-test-here/31257/2 "2022-01-05T14:27:47Z")

</div>

Hey @swasthik08

What have you tried so far? What’s failing for you?

---

<div class="post-metadata">

**Author:** ![swasthik08](https://avatars.discourse-cdn.com/v4/letter/s/dfb087/32.png) [@swasthik08](https://community.postman.com/u/swasthik08)\
**Post date:** [January 5, 2022, 2:46pm UTC](https://community.postman.com/t/need-help-in-writting-a-test-here/31257/3 "2022-01-05T14:46:59Z")

</div>

```auto
var jsonData = pm.response.json();
const key2 = jsonData.data.find(u => u.key2 === '100')
const key1 = key2 ? key2.metric : 'not found'

pm.test("Verify Analysis shown is correct", function () {
    var jsonData = pm.response.json();
    pm.expect(key2.metric).to.eql(4);

```

I tried this and it worked but As I have to assert many keys and many objects …is there any better /optimized scripts to reuse it for each objects in array
