How to put an array in a json object.

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 ← 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!

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) }},


}’