# Help on checking items in response

**URL:** <https://community.postman.com/t/help-on-checking-items-in-response/18219>\
**Category:** Help Hub\
**Tags:** tests\
**Created:** [December 4, 2020, 1:47am UTC](https://community.postman.com/t/help-on-checking-items-in-response/18219 "2020-12-04T01:47:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mpnistal19](https://avatars.discourse-cdn.com/v4/letter/m/3ab097/32.png) [@mpnistal19](https://community.postman.com/u/mpnistal19)\
**Post date:** [December 4, 2020, 1:47am UTC](https://community.postman.com/t/help-on-checking-items-in-response/18219/1 "2020-12-04T01:47:17Z")

</div>

**Your question may already have an answer on the community forum. Please search for related topics, and then read through the [guidelines](https://community.postman.com/t/about-the-help-category/38) before creating a new topic.**

Hello everyone,

Is there any way for postman to check if a specified field contains one or more items below. For a sample response below:

```
{
    "id": "4090ecfa537e83f33ebaf4bb368e2b0f",
    "r": {
        "UsedBy": [
            {
                "id": "f44fb93d09c188624ef2d53c89a4237e",
                "type": "Parameter",
                "name": "ASDF123"
            },
            {
                "id": "ce3a770f4d4d9057fa8ad11f269ada87",
                "type": "Parameter",
                "name": "QWERT123"
            }
        ]
    }
}

```

Say, if there are any items below **r:** (UsedBy[0] and [1] in this case), the test **passes**.

But an empty list such as below **fails** the test:

```
{
    "id": "4090ecfa537e83f33ebaf4bb368e2b0f",
    "r": {}
}
```

---

<div class="post-metadata">

**Author:** ![bpricilla](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/bpricilla/32/6511_2.png) [@bpricilla](https://community.postman.com/u/bpricilla)\
**Post date:** [December 4, 2020, 2:04am UTC](https://community.postman.com/t/help-on-checking-items-in-response/18219/2 "2020-12-04T02:04:11Z")

</div>

Hello @mpnistal19 , so you are telling that just the property “r” presence should pass the Test cases?

In that case, please check that the below snippet works for you 🙂

```auto
var resp = JSON.parse(responseBody);

 pm.test("'r' property availbility check", function()
{
  pm.expect(resp.r).to.exist);
});

```

If this doesn’t answer your question, kindly share your Test and explain what are you trying to Test.

---

<div class="post-metadata">

**Author:** ![mpnistal19](https://avatars.discourse-cdn.com/v4/letter/m/3ab097/32.png) [@mpnistal19](https://community.postman.com/u/mpnistal19)\
**Post date:** [December 4, 2020, 2:16am UTC](https://community.postman.com/t/help-on-checking-items-in-response/18219/3 "2020-12-04T02:16:57Z")

</div>

> [@bpricilla](#):
>
> `var resp = JSON.parse(responseBody);`

Thanks @bpricilla will try it. 🙂 Basically, if there’s anything inside “r”: {} it’ll pass the test.

It’s actually one of my first steps, soon I will have to check for specific numbers of items under **r** but for one I willjust have to verify if there’s anything under.

---

<div class="post-metadata">

**Author:** ![michal.robaszewski.j](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michal.robaszewski.j/32/5378_2.png) [@michal.robaszewski.j](https://community.postman.com/u/michal.robaszewski.j)\
**Post date:** [December 4, 2020, 10:06am UTC](https://community.postman.com/t/help-on-checking-items-in-response/18219/4 "2020-12-04T10:06:34Z")

</div>

Hello  
This test will check if given key contains R key and in next it will test if it contain at least on of the given keys

```auto
if(pm.response.to.be.success){
    pm.test("respons has R key", function() {
      pm.expect(pm.response.json()).to.have.property('r');
    });
    
    pm.test("R key is an object", function() {
      pm.expect(pm.response.json().r).to.be.an('object').that.has.any.keys('UsedBy');
    });
}

```

You can change `.any.keys` to `.all.keys` if you expect only this one key or list of them to appear.  
More you can find in official docs

> **[Expect / Should - Chai](https://www.chaijs.com/api/bdd/#method_keys)**

---

<div class="post-metadata">

**Author:** ![mpnistal19](https://avatars.discourse-cdn.com/v4/letter/m/3ab097/32.png) [@mpnistal19](https://community.postman.com/u/mpnistal19)\
**Post date:** [December 6, 2020, 12:45am UTC](https://community.postman.com/t/help-on-checking-items-in-response/18219/5 "2020-12-06T00:45:48Z")

</div>

Thank you very much, pal. I got a lot of help from the resources you shared.
