# Checking JSON respond with test script

**URL:** <https://community.postman.com/t/checking-json-respond-with-test-script/7340>\
**Category:** Help Hub\
**Tags:** tests, json, response\
**Created:** [August 22, 2019, 10:55am UTC](https://community.postman.com/t/checking-json-respond-with-test-script/7340 "2019-08-22T10:55:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Coxjeffrey](https://avatars.discourse-cdn.com/v4/letter/c/b3f665/32.png) [@Coxjeffrey](https://community.postman.com/u/Coxjeffrey)\
**Post date:** [August 22, 2019, 10:55am UTC](https://community.postman.com/t/checking-json-respond-with-test-script/7340/1 "2019-08-22T10:55:47Z")

</div>

Hello there,

I’m trying to check a value from the JSON respond I get.

The JSON Body I get is:

```
{
    "HolidayRightsResults": [
        {
            "NiszNumber": "78121925128",
            "HolidayRights": [
                {
                    "AFWZ_TYP": "01",
                    "BGN_DAT": "2019-01-01T00:00:00",
                    "BGN_SLD_OPN_DG": 20.00,
                    "BGN_SLD_OPN_URN": 152.00,
                    "BRK_RCHT_DG": 20.00,
                    "BRK_RCHT_URN": 152.00,
                    "DSSR_NR": "1HI0269",
                    "DateIn": "2014-08-01T00:00:00",
                    "DateOut": null,
                    "END_DAT": "2020-01-01T00:00:00",
                    "OPGN_DG": 4.00,
                    "OPGN_URN": 30.40,
                    "Hrk_cod": "S",
                    "WNNR": "0001876",
                    "OPGB_RCHT_URN": 152.00,
                    "OPGB_RCHT_DGN": 20.00,
                    "RCHT_DG_WZG_DT": "2019-08-21T07:51:21.296431",
                    "RCHT_URN_WZG_DT": "2019-08-21T07:51:21.296431",
                    "RCHT_EXPRT_DT": "2019-08-21T07:51:37.309306"
                }
            ],
            "CalculationMessages": []
        }
    ]
}

```

What I’m trying to do is to check the NiszNumber.  
My test script is:

```
var response = JSON.parse(responseBody);
tests["Nisznumber is 78121925128"] = response.HolidayRightsResults.NiszNumber == 78121925128;

```

All I’m getting is an error.

---

<div class="post-metadata">

**Author:** ![bhargavkaranam96](https://avatars.discourse-cdn.com/v4/letter/b/e99b99/32.png) [@bhargavkaranam96](https://community.postman.com/u/bhargavkaranam96)\
**Post date:** [August 22, 2019, 11:29am UTC](https://community.postman.com/t/checking-json-respond-with-test-script/7340/2 "2019-08-22T11:29:34Z")

</div>

Hi @Coxjeffrey,  
You seem to be accessing `NiszNumber` incorrectly. `HolidayRightsResults` is an array of objects. So you should be accessing it this way instead, `response.HolidayRightsResults[0].NiszNumber`

Additionally, you can use the newer syntax to write tests and use Lodash (in built in Postman sandbox) to access properties in objects

```javascript
pm.test('Nisznumber is 78121925128', function () {
  expect(_.get(response, 'HolidayRightsResults.0.NiszNumber')).to.eql(78121925128);
});

```

[https://learning.getpostman.com/docs/postman/scripts/test\_scripts/](https://learning.getpostman.com/docs/postman/scripts/test_scripts/)  
[https://learning.getpostman.com/docs/postman/scripts/postman\_sandbox/](https://learning.getpostman.com/docs/postman/scripts/postman_sandbox/)

---

<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:** [August 22, 2019, 11:34am UTC](https://community.postman.com/t/checking-json-respond-with-test-script/7340/3 "2019-08-22T11:34:23Z")

</div>

I also wrote something about accessing different parts of a JSON response that might be useful:

> [@Sharing tips and tricks with others in the Postman community](https://community.postman.com/t/sharing-tips-and-tricks-with-others-in-the-postman-community/5123/5):
>
> Extracting values from a JSON response I notice lots of questions from the community which all have a similar flavour - Users are having trouble extracting data from a JSON response body when the value is within an array. These are normally JavaScript related questions, more than specific Postman questions but I want to use this thread to offer more support around this problem. For these examples I’ll be using the [https://randomuser.me](https://randomuser.me) API, this returns lots of random user data, in a JSON form…
