# creating json inline

**URL:** <https://forum.ansible.com/t/creating-json-inline/14379>\
**Category:** Ansible Project\
**Created:** [January 20, 2014, 2:55am UTC](https://forum.ansible.com/t/creating-json-inline/14379 "2014-01-20T02:55:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jim1](https://avatars.discourse-cdn.com/v4/letter/j/779978/32.png) [@jim1](https://forum.ansible.com/u/jim1)\
**Post date:** [January 20, 2014, 2:55am UTC](https://forum.ansible.com/t/creating-json-inline/14379/1 "2014-01-20T02:55:33Z")

</div>

An API that I use accepts only JSON. I’m creating what I need with set\_fact, which I’ll later use with the uri module. However, the curly braces are getting interpreted as a dictionary or something.

Here’s my playbook:

---

<div class="post-metadata">

**Author:** ![James\_Cammarata1](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@James\_Cammarata1](https://forum.ansible.com/u/James_Cammarata1)\
**Post date:** [January 20, 2014, 2:36pm UTC](https://forum.ansible.com/t/creating-json-inline/14379/2 "2014-01-20T14:36:43Z")

</div>

Escape those braces:

- set\_fact: \>  
sshkey\_json=‘{“text”: “{{public\_key\_contents.stdout}}”}’

results in:

TASK: [debug var=sshkey\_json] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [127.0.0.1] =\> {  
“sshkey\_json”: “\{"text": "ssh-rsa blahblah comment"\}”  
}

Which I think is what you want.

---

<div class="post-metadata">

**Author:** ![jim1](https://avatars.discourse-cdn.com/v4/letter/j/779978/32.png) [@jim1](https://forum.ansible.com/u/jim1)\
**Post date:** [January 20, 2014, 3:53pm UTC](https://forum.ansible.com/t/creating-json-inline/14379/3 "2014-01-20T15:53:45Z")

</div>

Hmm, that was what I thought I wanted, but using that value for the API call was refused as it was not valid JSON.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [January 21, 2014, 12:43am UTC](https://forum.ansible.com/t/creating-json-inline/14379/4 "2014-01-21T00:43:23Z")

</div>

Might be easier to just declare it as YAML.

If you need it as a string, there’s stuff like

{{ foo | to\_json }}
