# Loop over list of dicts in ansible

**URL:** <https://forum.ansible.com/t/loop-over-list-of-dicts-in-ansible/33247>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [June 24, 2020, 1:02pm UTC](https://forum.ansible.com/t/loop-over-list-of-dicts-in-ansible/33247 "2020-06-24T13:02:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![BIJAY\_PARIDA](https://avatars.discourse-cdn.com/v4/letter/b/7feea3/32.png) [@BIJAY\_PARIDA](https://forum.ansible.com/u/BIJAY_PARIDA)\
**Post date:** [June 24, 2020, 1:02pm UTC](https://forum.ansible.com/t/loop-over-list-of-dicts-in-ansible/33247/1 "2020-06-24T13:02:02Z")

</div>

I have a list of dicst like this -

“lv”: [  
{  
“CreatedDate”: “2020-06-23T16:49:55.504+0000”,  
“Description”: “Layer 0”,  
“LayerVersionArn”: “arn:aws:lambda:us-east-1”,  
“Version”: 10  
},  
{  
“CreatedDate”: “2020-06-23T16:44:26.011+0000”,  
“Description”: “Layer 1”,  
“LayerVersionArn”: “arn:aws:lambda:us-east-1”,  
“Version”: 9  
}  
]

I want to get the list of **Version (10 and 9 above)** field from the list. Note - Number of elements in the list is not static.

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [June 24, 2020, 2:49pm UTC](https://forum.ansible.com/t/loop-over-list-of-dicts-in-ansible/33247/2 "2020-06-24T14:49:42Z")

</div>

Try this

&nbsp;&nbsp;- set\_fact:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;versions: "{{ lv|map(attribute='Version')|list }}"

---

<div class="post-metadata">

**Author:** ![BIJAY\_PARIDA](https://avatars.discourse-cdn.com/v4/letter/b/7feea3/32.png) [@BIJAY\_PARIDA](https://forum.ansible.com/u/BIJAY_PARIDA)\
**Post date:** [June 24, 2020, 8:47pm UTC](https://forum.ansible.com/t/loop-over-list-of-dicts-in-ansible/33247/3 "2020-06-24T20:47:22Z")

</div>

Thanks Vladimir.

This also worked-

- set\_fact:  
versions: “{{ (lv | json\_query(‘[\*].Version’) }}”
