# Parsing json output issues

**URL:** <https://forum.ansible.com/t/parsing-json-output-issues/36405>\
**Category:** Ansible Project\
**Created:** [March 7, 2022, 3:17am UTC](https://forum.ansible.com/t/parsing-json-output-issues/36405 "2022-03-07T03:17:37Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Delmiro\_Campelo](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@Delmiro\_Campelo](https://forum.ansible.com/u/Delmiro_Campelo)\
**Post date:** [March 7, 2022, 3:17am UTC](https://forum.ansible.com/t/parsing-json-output-issues/36405/1 "2022-03-07T03:17:37Z")

</div>

Hello Ansible friends,

I’m hoping that you can provide some assistance here. I’m trying to parsed through json response from a web application, but I’m having some issues. The goal of this playbook is to display the site-id for all routers in the json response. Any help is appreciated, thank you.

**Here is the ansible playbook.**

- hosts: vmanage  
connection: local  
gather\_facts: no  
tasks:

- vmanage\_device\_facts:  
user: “{{ ansible\_user }}”  
host: “{{ ansible\_host }}”  
password: “{{ ansible\_password }}”  
register: output

- name: Create device dictionary  
set\_fact:  
device\_status: ‘{{ output | json\_query(“vedges[0].[“side-id”]”)}}’

- name: Print out site ids  
debug:  
msg: “{{ device\_status }}”

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [March 7, 2022, 6:02am UTC](https://forum.ansible.com/t/parsing-json-output-issues/36405/2 "2022-03-07T06:02:10Z")

</div>

> Hello Ansible friends,
> 
> I’m hoping that you can provide some assistance here. I’m trying to parsed through json response from a web application, but I’m having some issues. The goal of this playbook is to display the site-id for all routers in the json response. Any help is appreciated, thank you.
> 
> **Here is the ansible playbook.**
> 
> - hosts: vmanage  
> connection: local  
> gather\_facts: no  
> tasks:
> 
> - vmanage\_device\_facts:  
> user: “{{ ansible\_user }}”  
> host: “{{ ansible\_host }}”  
> password: “{{ ansible\_password }}”  
> register: output
> 
> - name: Create device dictionary  
> set\_fact:  
> device\_status: ‘{{ output | json\_query(“vedges[0].[“side-id”]”)}}’

Try quoting side-id with backticks

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [March 7, 2022, 9:57am UTC](https://forum.ansible.com/t/parsing-json-output-issues/36405/3 "2022-03-07T09:57:22Z")

</div>

Backticks don't work I see. This should do it:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;device\_status: "{{ output | json\_query('vedges[0].[\'side-id\']') }}"

---

<div class="post-metadata">

**Author:** ![Delmiro\_Campelo](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@Delmiro\_Campelo](https://forum.ansible.com/u/Delmiro_Campelo)\
**Post date:** [March 7, 2022, 2:07pm UTC](https://forum.ansible.com/t/parsing-json-output-issues/36405/4 "2022-03-07T14:07:48Z")

</div>

Thank you for your reply Dick, the backspace didn’t work here, please see error below. I tried all kinds of combinations ☹ Do you have any other ideas?

PLAY [vmanage] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [vmanage\_device\_facts] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
[WARNING]: Module did not set no\_log for password  
ok: [10.10.2.2]

TASK [parse through output] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [10.10.2.2]: FAILED! =\> {“msg”: “template error while templating string: expected token ‘,’, got ‘side’. String: device\_status:"{{ output | json\_query(‘vedges[0].[\\‘side-id\\’]’) }}"”}

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
10.10.2.2 : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [March 7, 2022, 2:59pm UTC](https://forum.ansible.com/t/parsing-json-output-issues/36405/5 "2022-03-07T14:59:24Z")

</div>

Did you try this literal string?

device\_status: "{{ output | json\_query('vedges[0].[\'side-id\']') }}"

---

<div class="post-metadata">

**Author:** ![Delmiro\_Campelo](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@Delmiro\_Campelo](https://forum.ansible.com/u/Delmiro_Campelo)\
**Post date:** [March 7, 2022, 5:39pm UTC](https://forum.ansible.com/t/parsing-json-output-issues/36405/6 "2022-03-07T17:39:58Z")

</div>

Yes I did, see the playbook below please.

- hosts: vmanage  
connection: local  
gather\_facts: no  
tasks:

- vmanage\_device\_facts:  
user: “{{ ansible\_user }}”  
host: “{{ ansible\_host }}”  
password: “{{ ansible\_password }}”  
register: output

- name: parse through output  
set\_fact:  
device\_status:“{{ output | json\_query(‘vedges[0].['side-id']’) }}”

- name: Print out neighbors  
debug:  
msg: “{{ device\_status }}”

---

<div class="post-metadata">

**Author:** ![Hamza\_Bouabdallah](https://avatars.discourse-cdn.com/v4/letter/h/439d5e/32.png) [@Hamza\_Bouabdallah](https://forum.ansible.com/u/Hamza_Bouabdallah)\
**Post date:** [March 7, 2022, 10:01pm UTC](https://forum.ansible.com/t/parsing-json-output-issues/36405/7 "2022-03-07T22:01:33Z")

</div>

Try converting the data to something that ansible can parse using the **from\_json** filter, then just access it using the json path that in your case ends with **vedges[0][‘side-id’]**  
Also why do put a dot between [0] and [‘side-id’] ? no need

---

<div class="post-metadata">

**Author:** ![Delmiro\_Campelo](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@Delmiro\_Campelo](https://forum.ansible.com/u/Delmiro_Campelo)\
**Post date:** [March 17, 2022, 10:29pm UTC](https://forum.ansible.com/t/parsing-json-output-issues/36405/8 "2022-03-17T22:29:26Z")

</div>

for some reason, I couldn’t get it to work. I ended up using Ansible URI module to get the information from API and parse it after. It works now. Thank you to all that responded.
