# Problem in passing JSON string in environment to shell module

**URL:** <https://forum.ansible.com/t/problem-in-passing-json-string-in-environment-to-shell-module/23256>\
**Category:** Ansible Project\
**Created:** [December 14, 2016, 1:53pm UTC](https://forum.ansible.com/t/problem-in-passing-json-string-in-environment-to-shell-module/23256 "2016-12-14T13:53:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nirav\_Radia](https://avatars.discourse-cdn.com/v4/letter/n/90ced4/32.png) [@Nirav\_Radia](https://forum.ansible.com/u/Nirav_Radia)\
**Post date:** [December 14, 2016, 1:53pm UTC](https://forum.ansible.com/t/problem-in-passing-json-string-in-environment-to-shell-module/23256/1 "2016-12-14T13:53:29Z")

</div>

I am trying to pass JSON string in environment.

`

- name: Start {{service\_name}}  
shell: “\<\> --server.port={{service\_port}}"”  
environment:
- SPRING\_APPLICATION\_JSON: ‘{“test-host.1”:“{{test\_host\_1}}”,“test-host.2”:“{{test\_host\_2}}”}’  
`

test\_host\_1 is 172.31.00.00

test\_host\_2 is 172.31.00.00

But when in spring logs, I get JSON parse exception where it prints

`Caused by: com.fasterxml.jackson.core.JsonParseException: Unexpected character (''' (code 39)): was expecting double-quote to start field name at [Source: {'test-host.1': '172.31.00.00', 'test-host.2': '172.31.00.00'}; line: 1, column: 3]`

As seen, double quotes are converted to single quotes !!!

I tried escaping double quotes but with no luck.

Any idea why it happens, or any work around?

Thanks,  
Nirav

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [December 14, 2016, 6:47pm UTC](https://forum.ansible.com/t/problem-in-passing-json-string-in-environment-to-shell-module/23256/2 "2016-12-14T18:47:39Z")

</div>

> I am trying to pass JSON string in environment.
> 
> - name: Start {{service\_name}}  
> &nbsp;&nbsp;shell: "\<\<starting springboot jar\>\> --server.port={{service\_port}}\""  
> &nbsp;&nbsp;environment:  
> &nbsp;&nbsp;&nbsp;&nbsp;- SPRING\_APPLICATION\_JSON:  
> '{"test-host.1":"{{test\_host\_1}}","test-host.2":"{{test\_host\_2}}"}'

As a workaround you can add a space after the first single quote like this  
' {"test-host.1":"{{test\_host\_1}}","test-host.2":"{{test\_host\_2}}"}'

> test\_host\_1 is 172.31.00.00  
> test\_host\_2 is 172.31.00.00
> 
> But when in spring logs, I get JSON parse exception where it prints
> 
> Caused by: com.fasterxml.jackson.core.JsonParseException: Unexpected  
> character (''' (code 39)): was expecting double-quote to start field name  
> at [Source: {'test-host.1': '172.31.00.00', 'test-host.2': '172.31.00.00'};  
> line: 1, column: 3]
> 
> As seen, double quotes are converted to single quotes !!!
> 
> I tried escaping double quotes but with no luck.
> 
> Any idea why it happens, or any work around?

No idea why, but it looks like a bug to me.
