# set\_fact with single item array gets flattened -- by design?

**URL:** <https://forum.ansible.com/t/set-fact-with-single-item-array-gets-flattened-by-design/21864>\
**Category:** Ansible Project\
**Created:** [June 27, 2016, 11:19am UTC](https://forum.ansible.com/t/set-fact-with-single-item-array-gets-flattened-by-design/21864 "2016-06-27T11:19:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Barry\_Kaplan](https://avatars.discourse-cdn.com/v4/letter/b/48db29/32.png) [@Barry\_Kaplan](https://forum.ansible.com/u/Barry_Kaplan)\
**Post date:** [June 27, 2016, 11:19am UTC](https://forum.ansible.com/t/set-fact-with-single-item-array-gets-flattened-by-design/21864/1 "2016-06-27T11:19:53Z")

</div>

(ansible 2.1)

I have a set\_fact like:

- name: Get plant agent data from consul  
set\_fact:  
myfact: “{{ lookup(‘consul\_kv’, ‘mykey recurse=true’) }}”

When the lookup returns an array of size \>= 2, ‘myfact’ is assigned the array value.

But when the lookup returns an array of size == 1, ‘myfact’ is assigned the _single object_ at index 0 of the array. The result is arrays of size one are flattened into an dict.

Is this by design? Some kind of attempted helpfulness? Its causing all kinds of grief because subsequent uses of this fact can’t depend on it being an array of dict or just a simple dict.
