# URI modul / json body / variable with "-" returned

**URL:** <https://forum.ansible.com/t/uri-modul-json-body-variable-with-returned/15524>\
**Category:** Ansible Project\
**Created:** [June 23, 2014, 11:52am UTC](https://forum.ansible.com/t/uri-modul-json-body-variable-with-returned/15524 "2014-06-23T11:52:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sascha.lucas](https://avatars.discourse-cdn.com/v4/letter/s/9fc348/32.png) [@sascha.lucas](https://forum.ansible.com/u/sascha.lucas)\
**Post date:** [June 23, 2014, 11:52am UTC](https://forum.ansible.com/t/uri-modul-json-body-variable-with-returned/15524/1 "2014-06-23T11:52:06Z")

</div>

Hi,

I’m using the URI module with a REST/json API. First I’m logging on, to get a token, wich I want to use in further requests. Its seems that the returnded token contains a “-” (minus sign) in its key name. I know that “-” ist not a valide ansible variable. And this seems to be a problem:

- name: REST logon  
uri: url=“[http://XXXXXXX/rest/logon](http://XXXXXXX/rest/logon)” method=“POST” HEADER\_Content-Type=“application/json” user=“XXXXXX” password=“XXXXXX”  
register: logon

- debug: msg=“{{ logon.json.Dcnm-Token }}”

$ ansible-playbook -v play.yml  
PLAY [test] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK: [REST logon] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [XXXXXXX] =\> {“changed”: false, “content\_length”: “61”, “content\_type”: “application/json”, “date”: “Mon, 23 Jun 2014 11:46:54 GMT”, “json”: {“Dcnm-Token”: “/isIApYCIM12Ms50gfjlX/ppLkNeuCp1wZHKQKHB2N8=”}, “redirected”: false, “server”: “Apache”, “status”: 200}

TASK: [debug msg=“{{logon.json.Dcnm-Token}}”] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [XXXXXX] =\> unable to look up a name or access an attribute in template string

In other places (i.e. facts) “-” is convertet to “\_”. This seems not to be the case here (ansible 1.4.4). Are there any options?

Thanks, Sascha.

---

<div class="post-metadata">

**Author:** ![Christian\_Thiemann](https://avatars.discourse-cdn.com/v4/letter/c/f04885/32.png) [@Christian\_Thiemann](https://forum.ansible.com/u/Christian_Thiemann)\
**Post date:** [June 23, 2014, 12:52pm UTC](https://forum.ansible.com/t/uri-modul-json-body-variable-with-returned/15524/2 "2014-06-23T12:52:02Z")

</div>

Use array syntax:

- debug: msg=“{{ logon.json[‘Dcnm-Token’] }}”

---

<div class="post-metadata">

**Author:** ![sascha.lucas](https://avatars.discourse-cdn.com/v4/letter/s/9fc348/32.png) [@sascha.lucas](https://forum.ansible.com/u/sascha.lucas)\
**Post date:** [June 23, 2014, 1:55pm UTC](https://forum.ansible.com/t/uri-modul-json-body-variable-with-returned/15524/3 "2014-06-23T13:55:10Z")

</div>

Thanks, this did the trick. Sascha.
