# ansible playbook in json format not working

**URL:** <https://forum.ansible.com/t/ansible-playbook-in-json-format-not-working/30662>\
**Category:** Ansible Project\
**Created:** [June 26, 2019, 10:08pm UTC](https://forum.ansible.com/t/ansible-playbook-in-json-format-not-working/30662 "2019-06-26T22:08:24Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Narahari\_n\_Savitha](https://avatars.discourse-cdn.com/v4/letter/n/8e8cbc/32.png) [@Narahari\_n\_Savitha](https://forum.ansible.com/u/Narahari_n_Savitha)\
**Post date:** [June 26, 2019, 10:08pm UTC](https://forum.ansible.com/t/ansible-playbook-in-json-format-not-working/30662/1 "2019-06-26T22:08:24Z")

</div>

Hello Folkds:

Thank you in advance for your time and attention.

I wrote a playbook in the json format.

> [  
> {  
> “name”: “Test the json mode”  
> “hosts”: “cool\_columbus”,  
> “tasks”: [  
> {  
> “name”: “First task”  
> “shell”: {  
> “chdir”: “/tmp”,  
> “free\_form”: “ls -l”,  
> }  
> }  
> ]  
> }  
> ]

when I run it with the command

> > ansible-playbook test\_playbook.json
> 
> > ERROR! Syntax Error while loading YAML.
> 
> > expected ‘,’ or ‘}’, but got ‘’
> 
> > 
> 
> > The error appears to have been in ‘/home/pidansible/test\_playbook.json’: line 4, column 5, but may
> 
> > be elsewhere in the file depending on the exact syntax problem.
> 
> > 
> 
> > The offending line appears to be:

What am I doing wrong and how to run this ?

Please help.

-N

---

<div class="post-metadata">

**Author:** ![Michael\_M1](https://avatars.discourse-cdn.com/v4/letter/m/e274bd/32.png) [@Michael\_M1](https://forum.ansible.com/u/Michael_M1)\
**Post date:** [June 26, 2019, 11:17pm UTC](https://forum.ansible.com/t/ansible-playbook-in-json-format-not-working/30662/2 "2019-06-26T23:17:50Z")

</div>

Playbooks must be in yaml. Inventories can be in json (at least dynamic inventories require it), but not the playbooks themselves.

---

<div class="post-metadata">

**Author:** ![cassell](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@cassell](https://forum.ansible.com/u/cassell)\
**Post date:** [June 26, 2019, 11:20pm UTC](https://forum.ansible.com/t/ansible-playbook-in-json-format-not-working/30662/3 "2019-06-26T23:20:29Z")

</div>

> Hello Folkds:
> 
> Thank you in advance for your time and attention.
> 
> I wrote a playbook in the json format.
> 
> \> [  
> \> {  
> \> "name": "Test the json mode"

Missing a comma.

> \> "hosts": "cool\_columbus",  
> \> "tasks": [  
> \> {  
> \> "name": "First task"

Missing comma.

> \> "shell": {  
> \> "chdir": "/tmp",  
> \> "free\_form": "ls -l",  
> \> }  
> \> }  
> \> ]  
> \> }  
> \> ]
> 
> when I run it with the command
> 
> \>\> ansible-playbook test\_playbook.jsonERROR! Syntax Error while loading YAML. expected ',' or '}', but got '\<scalar\>'  
> \>\> The error appears to have been in '/home/pidansible/test\_playbook.json': line 4, column 5, but maybe elsewhere in the file depending on the exact syntax problem.  
> \>\> The offending line appears to be:
> 
> What am I doing wrong and how to run this ?
> 
> Please help.
> 
> -N

V/r,  
James Cassell

---

<div class="post-metadata">

**Author:** ![Narahari\_n\_Savitha](https://avatars.discourse-cdn.com/v4/letter/n/8e8cbc/32.png) [@Narahari\_n\_Savitha](https://forum.ansible.com/u/Narahari_n_Savitha)\
**Post date:** [June 27, 2019, 4:32am UTC](https://forum.ansible.com/t/ansible-playbook-in-json-format-not-working/30662/4 "2019-06-27T04:32:23Z")

</div>

Thank You James for pointing out the mistakes.

I fixed them and now the json playbook works.

---

<div class="post-metadata">

**Author:** ![Narahari\_n\_Savitha](https://avatars.discourse-cdn.com/v4/letter/n/8e8cbc/32.png) [@Narahari\_n\_Savitha](https://forum.ansible.com/u/Narahari_n_Savitha)\
**Post date:** [June 27, 2019, 4:33am UTC](https://forum.ansible.com/t/ansible-playbook-in-json-format-not-working/30662/5 "2019-06-27T04:33:25Z")

</div>

James pointed out the mistakes in the json and now it works.  
I am able to use json as valid format for playboks.

---

<div class="post-metadata">

**Author:** ![Narahari\_n\_Savitha](https://avatars.discourse-cdn.com/v4/letter/n/8e8cbc/32.png) [@Narahari\_n\_Savitha](https://forum.ansible.com/u/Narahari_n_Savitha)\
**Post date:** [June 27, 2019, 4:36am UTC](https://forum.ansible.com/t/ansible-playbook-in-json-format-not-working/30662/6 "2019-06-27T04:36:33Z")

</div>



---

<div class="post-metadata">

**Author:** ![Angel\_Rengifo\_Cancin](https://avatars.discourse-cdn.com/v4/letter/a/9e8a1a/32.png) [@Angel\_Rengifo\_Cancin](https://forum.ansible.com/u/Angel_Rengifo_Cancin)\
**Post date:** [June 27, 2019, 6:48pm UTC](https://forum.ansible.com/t/ansible-playbook-in-json-format-not-working/30662/7 "2019-06-27T18:48:54Z")

</div>

Just for curiosity, why are you using json instead of yaml?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [June 28, 2019, 5:04pm UTC](https://forum.ansible.com/t/ansible-playbook-in-json-format-not-working/30662/8 "2019-06-28T17:04:13Z")

</div>

JSON is a subset of YAML, so anything you see in YAML can be done in  
JSON, .. the real question is SHOULD YOU?
