# How to have a space in a variable from a JSON payload returned by uri module

**URL:** <https://forum.ansible.com/t/how-to-have-a-space-in-a-variable-from-a-json-payload-returned-by-uri-module/24891>\
**Category:** Ansible Project\
**Created:** [July 4, 2017, 1:05pm UTC](https://forum.ansible.com/t/how-to-have-a-space-in-a-variable-from-a-json-payload-returned-by-uri-module/24891 "2017-07-04T13:05:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rasmus\_Sjorslev](https://avatars.discourse-cdn.com/v4/letter/r/5f8ce5/32.png) [@Rasmus\_Sjorslev](https://forum.ansible.com/u/Rasmus_Sjorslev)\
**Post date:** [July 4, 2017, 1:05pm UTC](https://forum.ansible.com/t/how-to-have-a-space-in-a-variable-from-a-json-payload-returned-by-uri-module/24891/1 "2017-07-04T13:05:43Z")

</div>

Im using the uri module to call a REST endpoint but the JSON structure returns contains a space which im not sure how to escape.

First the call i make and register:

- name: Get subnet information (DNS, gateway, netmask etc.)  
uri:  
url: “{{ phpipam\_url }}/subnets/7/”  
method: GET  
headers:  
token: “{{ ipam\_login.json.data.token }}”  
status\_code: 200  
register: subnet\_info

subnet\_info then contains the JSON payload:

“json”: {  
“code”: 200,  
“data”: {  
“DNSrecords”: “1”,  
“DNSrecursive”: “1”,  
“allowRequests”: “1”,  
“calculation”: {  
“Broadcast”: “192.168.111.255”,  
“IP address”: “/”,  
“Max host IP”: “192.168.111.254”,  
“Min host IP”: “192.168.111.1”,  
“Network”: “192.168.111.0”,  
“Number of hosts”: 254,  
“Subnet Class”: “private C”,  
“Subnet bitmask”: “24”,  
“Subnet netmask”: “255.255.255.0”,  
“Subnet wildcard”: “0.0.0.255”,  
“Type”: “IPv4”

…

what i am after here is the Subnet netmask in the data.calculation but when i reference it like this:

“‘{{ subnet\_info.json.data.calculation.Subnet Netmask }}’”

or  
‘{{ subnet\_info.json.data.calculation.Subnet Netmask }}’

or  
“{{ subnet\_info.json.data.calculation.Subnet Netmask }}”

i get the following error:

fatal: [localhost]: FAILED! =\> {  
“failed”: true,  
“msg”: “template error while templating string: expected token ‘end of print statement’, got ‘Netmask’. String: ‘{{ subnet\_info.json.data.calculation.Subnet Netmask }}’”  
}

how can i get to that JSON data that contains a space and reference that as a variable?

---

<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 6, 2017, 9:07am UTC](https://forum.ansible.com/t/how-to-have-a-space-in-a-variable-from-a-json-payload-returned-by-uri-module/24891/2 "2017-07-06T09:07:20Z")

</div>

You can't use the dot notation when there are spaces, use square brackets instead.

"{{ subnet\_info.json.data.calculation['Subnet netmask'] }}"
