# How to check if exists property in json?

**URL:** <https://community.postman.com/t/how-to-check-if-exists-property-in-json/6602>\
**Category:** Help Hub\
**Tags:** tests, postman, exists\
**Created:** [July 17, 2019, 7:21pm UTC](https://community.postman.com/t/how-to-check-if-exists-property-in-json/6602 "2019-07-17T19:21:20Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![singhsivcan](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/singhsivcan/32/1595_2.png) [@singhsivcan](https://community.postman.com/u/singhsivcan)\
**Post date:** [July 18, 2019, 8:20am UTC](https://community.postman.com/t/how-to-check-if-exists-property-in-json/6602/3 "2019-07-18T08:20:54Z")

</div>

Hi @pablovok, just wanted to weigh in here about using [lodash which is inbuilt in Postman](https://learning.getpostman.com/docs/postman/scripts/postman_sandbox_api_reference/) and how you can easily get around this code piece.

Using the [`_.get`](https://lodash.com/docs/4.17.14#get) method from lodash, which allows safe extraction you’ll be able to avoid `try...catch` blocks.

```javascript
pm.test('Validate date', function () {
  var idDate = _.get(jsonData, 'date[0].id');

  if (idDate) {
    pm.expect(jsonData.date[0]).to.have.property('id');
  } else {
    pm.expect(jsonData.date).to.have.property('id');
    idDate = _.get(jsonData, 'date.id');
  }

  console.log(idDate);
  pm.environment.set('IdDATE - TEMP', idDate);
});

```

---

_[View the full topic](https://community.postman.com/t/how-to-check-if-exists-property-in-json/6602)._
