# Get JSONObject with a key in variable

**URL:** <https://forum.ansible.com/t/get-jsonobject-with-a-key-in-variable/28067>\
**Category:** Ansible Project\
**Created:** [July 17, 2018, 11:40am UTC](https://forum.ansible.com/t/get-jsonobject-with-a-key-in-variable/28067 "2018-07-17T11:40:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tommy.lin](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@tommy.lin](https://forum.ansible.com/u/tommy.lin)\
**Post date:** [July 17, 2018, 11:40am UTC](https://forum.ansible.com/t/get-jsonobject-with-a-key-in-variable/28067/1 "2018-07-17T11:40:17Z")

</div>

Hi Everyone,

May I is there a way to get an object/value from a JSONObject like this

{{ result[’ {{ keyName }} '] }}

For example:

result:  
{ “key1”: “value1”, “key2”: “value2” }

keyName: “key1”

Then the response for {{ result[’ {{ keyName }} '] }} should be “value1”

Thanks

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [July 17, 2018, 11:53am UTC](https://forum.ansible.com/t/get-jsonobject-with-a-key-in-variable/28067/2 "2018-07-17T11:53:13Z")

</div>

{{ result[keyName] }}

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [July 17, 2018, 12:53pm UTC](https://forum.ansible.com/t/get-jsonobject-with-a-key-in-variable/28067/3 "2018-07-17T12:53:16Z")

</div>

Here are some samples, expanding on Kai Stian Olstad’s response:

​
