# How to create a list from a hash

**URL:** <https://forum.ansible.com/t/how-to-create-a-list-from-a-hash/25874>\
**Category:** Ansible Project\
**Created:** [October 31, 2017, 11:53am UTC](https://forum.ansible.com/t/how-to-create-a-list-from-a-hash/25874 "2017-10-31T11:53:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abey\_Thomas](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@Abey\_Thomas](https://forum.ansible.com/u/Abey_Thomas)\
**Post date:** [October 31, 2017, 11:53am UTC](https://forum.ansible.com/t/how-to-create-a-list-from-a-hash/25874/1 "2017-10-31T11:53:13Z")

</div>

Hi,

I have got this hash

ok: [localhost] =\> {  
“msg”: {  
“123”: “hostname1”,  
“345”: “hostname2”  
}  
}

I would like to create a new list from the above hash which contains only the values .

- hostname1
- hostname2

When I use variable.keys() I get the first fields I would like all the second fields in a new list. Is this possible?

I got the hash after using combine().

Regards,  
Abey

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [November 4, 2017, 1:27am UTC](https://forum.ansible.com/t/how-to-create-a-list-from-a-hash/25874/2 "2017-11-04T01:27:59Z")

</div>

Something like this:

values: "{{ msg | json\_query('\*') }}"

---

<div class="post-metadata">

**Author:** ![Abey\_Thomas](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@Abey\_Thomas](https://forum.ansible.com/u/Abey_Thomas)\
**Post date:** [November 6, 2017, 1:28pm UTC](https://forum.ansible.com/t/how-to-create-a-list-from-a-hash/25874/3 "2017-11-06T13:28:47Z")

</div>

Hi Dick,

Thanks. That worked.

ok: [localhost] =\> {  
“msg”: [  
“hostname1”,  
“hostname1”  
]  
}

Never used JMESPath until now!

Abey
