# What is best practice to determine if object has property (ideally at any depth)?

**URL:** <https://forum.ansible.com/t/what-is-best-practice-to-determine-if-object-has-property-ideally-at-any-depth/23423>\
**Category:** Ansible Project\
**Created:** [January 11, 2017, 12:16am UTC](https://forum.ansible.com/t/what-is-best-practice-to-determine-if-object-has-property-ideally-at-any-depth/23423 "2017-01-11T00:16:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![james4](https://avatars.discourse-cdn.com/v4/letter/j/9f8e36/32.png) [@james4](https://forum.ansible.com/u/james4)\
**Post date:** [January 11, 2017, 12:16am UTC](https://forum.ansible.com/t/what-is-best-practice-to-determine-if-object-has-property-ideally-at-any-depth/23423/1 "2017-01-11T00:16:13Z")

</div>

What is the best way to test this condition?

when: “{{object is defined and object.property is defined and object.property.property is defined and object.property.property == ‘mystring’}}”

A custom lookup?

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [January 11, 2017, 8:49am UTC](https://forum.ansible.com/t/what-is-best-practice-to-determine-if-object-has-property-ideally-at-any-depth/23423/2 "2017-01-11T08:49:54Z")

</div>

What's best is always relative, but you could use this  
when: ((object | default()).property | default()).property | default() == 'mystring'

And remember, don't use curly brackets in when.
