# Variable in JSON

**URL:** <https://forum.ansible.com/t/variable-in-json/23709>\
**Category:** Ansible Project\
**Created:** [February 11, 2017, 2:49pm UTC](https://forum.ansible.com/t/variable-in-json/23709 "2017-02-11T14:49:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alok\_Ranjan1](https://avatars.discourse-cdn.com/v4/letter/a/22d042/32.png) [@Alok\_Ranjan1](https://forum.ansible.com/u/Alok_Ranjan1)\
**Post date:** [February 11, 2017, 2:49pm UTC](https://forum.ansible.com/t/variable-in-json/23709/1 "2017-02-11T14:49:59Z")

</div>

Dear All,

Can anyone please let me know how to use a register variable in JSON.

Where JSON is passed as an argument to a command using command module.

Any help or assistance would be highly appreciated.

Thanks,  
Alok

---

<div class="post-metadata">

**Author:** ![Nehal\_J\_Wani](https://avatars.discourse-cdn.com/v4/letter/n/a9a28c/32.png) [@Nehal\_J\_Wani](https://forum.ansible.com/u/Nehal_J_Wani)\
**Post date:** [February 15, 2017, 12:11pm UTC](https://forum.ansible.com/t/variable-in-json/23709/2 "2017-02-15T12:11:03Z")

</div>

Something like this should work:

[wani@linux tmp]$ cat a.yaml  
- hosts: localhost

&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;- command: 'echo {\"key\": \"value\"}'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: my\_output

&nbsp;&nbsp;&nbsp;&nbsp;- debug:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg: "{{ my\_output.stdout | from\_json }}"

On, run, it will show:

TASK [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /tmp/a.yaml:7  
ok: [localhost] =\> {  
&nbsp;&nbsp;&nbsp;&nbsp;"changed": false,  
&nbsp;&nbsp;&nbsp;&nbsp;"msg": {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"key": "value"  
&nbsp;&nbsp;&nbsp;&nbsp;}  
}
