# How to put an array in a json object.

**URL:** <https://forum.ansible.com/t/how-to-put-an-array-in-a-json-object/24942>\
**Category:** Ansible Project\
**Created:** [July 10, 2017, 4:05pm UTC](https://forum.ansible.com/t/how-to-put-an-array-in-a-json-object/24942 "2017-07-10T16:05:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![VenomMsk](https://avatars.discourse-cdn.com/v4/letter/v/eb9ed0/32.png) [@VenomMsk](https://forum.ansible.com/u/VenomMsk)\
**Post date:** [July 10, 2017, 4:05pm UTC](https://forum.ansible.com/t/how-to-put-an-array-in-a-json-object/24942/1 "2017-07-10T16:05:43Z")

</div>

Hi,

I have a varible that contains an array:

“AuthenticationHTTPheader”: [  
“iv-user”,  
“iv-groups”  
],

I need to pass this walue as a JSON-element in a body of a Request sent by URI module. So,

body:  
‘{  
…  
“remote\_http\_header”: “{{ item.AuthenticationHTTPheader|default (d\_remhed) }}”,  
…  
}’

in the output I see that URI module sends the following to the server:

“remote\_http\_header”: “[u’iv-user’, u’iv-groups’]”,

here → [https://stackoverflow.com/questions/41521138/ansible-template-adds-u-to-array-in-template](https://stackoverflow.com/questions/41521138/ansible-template-adds-u-to-array-in-template) ← I read, that " | to\_json" could solve the problem, but in my case using this breaks down the whole json of the body, it’s no more a json, but a string with escaped quotes:

…, "remote\_http\_header": "["iv-user", "iv-groups"]",…

how can I send to the server this array? I need this to be sent to the server:

“remote\_http\_header”: [“iv-user”, “iv-groups”]

Thanks to everybody!

---

<div class="post-metadata">

**Author:** ![VenomMsk](https://avatars.discourse-cdn.com/v4/letter/v/eb9ed0/32.png) [@VenomMsk](https://forum.ansible.com/u/VenomMsk)\
**Post date:** [July 13, 2017, 9:57am UTC](https://forum.ansible.com/t/how-to-put-an-array-in-a-json-object/24942/2 "2017-07-13T09:57:15Z")

</div>

My solution was:

1. Convert array variable into string:

{“ansible\_facts”: {“junction\_list”: [{“AuthenticationHTTPheader”: “[iv\_user, iv\_groups]”, …

1. Get rid of quotes in a body:

body:  
'{  
…  
“remote\_http\_header”: {{ item.AuthenticationHTTPheader|default (d\_remhed) }},

…  
}’
