# Complex variables and a key with a hyphen

**URL:** <https://forum.ansible.com/t/complex-variables-and-a-key-with-a-hyphen/30525>\
**Category:** Ansible Project\
**Created:** [June 10, 2019, 8:11pm UTC](https://forum.ansible.com/t/complex-variables-and-a-key-with-a-hyphen/30525 "2019-06-10T20:11:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gregor](https://avatars.discourse-cdn.com/v4/letter/g/6a8cbe/32.png) [@gregor](https://forum.ansible.com/u/gregor)\
**Post date:** [June 10, 2019, 8:11pm UTC](https://forum.ansible.com/t/complex-variables-and-a-key-with-a-hyphen/30525/1 "2019-06-10T20:11:04Z")

</div>

Hello Everyone,

I’m trying to reference a complex variable, but one of the words has a hyphen which breaks things.

Is there a way to set a fact the “specificVar” value from the last line in 1 set\_fact statement?  
So right now I’ve split up the setting the vars into two different set\_fact statements

set\_fact:  
intermediate\_var: “{{ example\_text[‘json’][‘output-parameters’] }}”  
set\_fact:  
machine\_var: “{{ intermediate\_var[0].value.string.value }}”

“json”: {  
“current-item-for-display”: “item0”,  
“name”: “Get-Stuff”,  
“output-parameters”: [  
{  
“name”: “machineName”,  
“scope”: “local”,  
“type”: “string”,  
“value”: {  
“string”: {  
“value”: “specificVar”

}

Many 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:** [June 10, 2019, 8:27pm UTC](https://forum.ansible.com/t/complex-variables-and-a-key-with-a-hyphen/30525/2 "2019-06-10T20:27:04Z")

</div>

> Hello Everyone,
> 
> I'm trying to reference a complex variable, but one of the words has a  
> hyphen which breaks things.

Breaks what? With notation hyphen is allowed.

> Is there a way to set a fact the "specificVar" value from the last line in  
> 1 set\_fact statement?  
> So right now I've split up the setting the vars into two different set\_fact  
> statements
> 
> set\_fact:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;intermediate\_var: "{{ example\_text['json']['output-parameters'] }}"  
> set\_fact:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;machine\_var: "{{ intermediate\_var[0].value.string.value }}"

Do what you have done

{{ example\_text['json']['output-parameters'][0].value.string.value }}

---

<div class="post-metadata">

**Author:** ![gregor](https://avatars.discourse-cdn.com/v4/letter/g/6a8cbe/32.png) [@gregor](https://forum.ansible.com/u/gregor)\
**Post date:** [June 10, 2019, 9:00pm UTC](https://forum.ansible.com/t/complex-variables-and-a-key-with-a-hyphen/30525/3 "2019-06-10T21:00:51Z")

</div>

I was trying to use all square brackets instead of mixing dot notation and brackets.  
Thanks for the quick answer Kia, works great.

---

<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:** [June 11, 2019, 5:10am UTC](https://forum.ansible.com/t/complex-variables-and-a-key-with-a-hyphen/30525/4 "2019-06-11T05:10:49Z")

</div>

That would be

{{ example\_text['json']['output-parameters'][0]['value']['string']['value'] }}
