# Conditionals based on empty JSON dict

**URL:** <https://forum.ansible.com/t/conditionals-based-on-empty-json-dict/24761>\
**Category:** Ansible Project\
**Created:** [June 19, 2017, 1:23pm UTC](https://forum.ansible.com/t/conditionals-based-on-empty-json-dict/24761 "2017-06-19T13:23:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Panagiotis\_Atmatzidi](https://avatars.discourse-cdn.com/v4/letter/p/a88e4f/32.png) [@Panagiotis\_Atmatzidi](https://forum.ansible.com/u/Panagiotis_Atmatzidi)\
**Post date:** [June 19, 2017, 1:23pm UTC](https://forum.ansible.com/t/conditionals-based-on-empty-json-dict/24761/1 "2017-06-19T13:23:33Z")

</div>

Hello list,

I’m trying to automate an API call that adds an ‘A’ record to the linode DNS service. The relevant playbook snippet is:

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [June 20, 2017, 8:54am UTC](https://forum.ansible.com/t/conditionals-based-on-empty-json-dict/24761/2 "2017-06-20T08:54:59Z")

</div>

Not tried, but wondering if you could use

- name: work out if create failed  
set\_fact:  
create\_a\_record\_failed: true  
when: linode\_api\_error.ERRORARRAY|length \> 0

to detect if you need to fail, then you can retrieve the error message in a separate step.

- fail: msg=“Setting DNS entry failed with error ‘{{ linode\_api\_error.ERRORARRAY.0.ERRORMESSAGE }}’”  
when:create\_a\_record\_failed|default(false)

(I think default(false) would get around the problem that you haven’t necessarily defined create\_a\_record\_failed if there is no error.
