# iterate over an array of dicts: find and register one of them

**URL:** <https://forum.ansible.com/t/iterate-over-an-array-of-dicts-find-and-register-one-of-them/24407>\
**Category:** Ansible Developer\
**Created:** [May 5, 2017, 8:08pm UTC](https://forum.ansible.com/t/iterate-over-an-array-of-dicts-find-and-register-one-of-them/24407 "2017-05-05T20:08:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ed\_Greenberg](https://avatars.discourse-cdn.com/v4/letter/e/7ab992/32.png) [@Ed\_Greenberg](https://forum.ansible.com/u/Ed_Greenberg)\
**Post date:** [May 5, 2017, 8:08pm UTC](https://forum.ansible.com/t/iterate-over-an-array-of-dicts-find-and-register-one-of-them/24407/1 "2017-05-05T20:08:29Z")

</div>

I have an array of dicts that came from the dnsmadeeasy module. I need to find the spf record.

The SPF record is a TXT record that begins ‘v=spf1’ and then continues on. I need to get the record, modify it, and put it back. I’m not worried about modifying it.

To get the record, I think I have to do this:

`

---

<div class="post-metadata">

**Author:** ![Tobias\_Wolf](https://avatars.discourse-cdn.com/v4/letter/t/eada6e/32.png) [@Tobias\_Wolf](https://forum.ansible.com/u/Tobias_Wolf)\
**Post date:** [May 7, 2017, 6:37pm UTC](https://forum.ansible.com/t/iterate-over-an-array-of-dicts-find-and-register-one-of-them/24407/2 "2017-05-07T18:37:53Z")

</div>

On way would be to use this new method that works a bit like the jq tool:

[http://docs.ansible.com/ansible/playbooks\_filters.html#json-query-filter](http://docs.ansible.com/ansible/playbooks_filters.html#json-query-filter)

I discovered this recently and it was pretty handy for munging nested data structures.

A loop using with\_subelements could work too:

[http://docs.ansible.com/ansible/playbooks\_loops.html#looping-over-subelements](http://docs.ansible.com/ansible/playbooks_loops.html#looping-over-subelements)

---

<div class="post-metadata">

**Author:** ![mohclips](https://avatars.discourse-cdn.com/v4/letter/m/df705f/32.png) [@mohclips](https://forum.ansible.com/u/mohclips)\
**Post date:** [May 9, 2017, 8:39pm UTC](https://forum.ansible.com/t/iterate-over-an-array-of-dicts-find-and-register-one-of-them/24407/3 "2017-05-09T20:39:24Z")

</div>

you can do most things with filters

(not tested)

- set\_fact: myvar=“{{ response | map(attribute=‘value’) | list }}”
