# need help for XML to JSON Parsing Error with Ansible using Parse\_xml

**URL:** <https://forum.ansible.com/t/need-help-for-xml-to-json-parsing-error-with-ansible-using-parse-xml/36815>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [July 7, 2022, 1:27pm UTC](https://forum.ansible.com/t/need-help-for-xml-to-json-parsing-error-with-ansible-using-parse-xml/36815 "2022-07-07T13:27:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![maulik\_patel](https://avatars.discourse-cdn.com/v4/letter/m/ec9cab/32.png) [@maulik\_patel](https://forum.ansible.com/u/maulik_patel)\
**Post date:** [July 7, 2022, 1:27pm UTC](https://forum.ansible.com/t/need-help-for-xml-to-json-parsing-error-with-ansible-using-parse-xml/36815/1 "2022-07-07T13:27:27Z")

</div>

hi ,

I was trying to parse a XML response to JSON using parse\_xml from an AWS VPN output, but I’m getting the below error.  
I am able to parse data with **“vpn\_conn\_facts.vpn\_connections[0].customer\_gateway\_configuration”** but, it is when I apply the filter parse\_xml, that the error arise.

**→ Error:**  
_**fatal: [localhost]: FAILED! =\> {“msg”: “Unexpected templating type error occurred on ({{ vpn\_conn\_facts.vpn\_connections[0].customer\_gateway\_configuration | parse\_xml(‘aws\_vpn\_parser.yaml’) }}): ‘NoneType’ object is not subscriptable”}**_

**→ playbook:**

---

<div class="post-metadata">

**Author:** ![maulik\_patel](https://avatars.discourse-cdn.com/v4/letter/m/ec9cab/32.png) [@maulik\_patel](https://forum.ansible.com/u/maulik_patel)\
**Post date:** [July 8, 2022, 6:37am UTC](https://forum.ansible.com/t/need-help-for-xml-to-json-parsing-error-with-ansible-using-parse-xml/36815/2 "2022-07-08T06:37:14Z")

</div>

anyone here to help me out with this please ? thanks…

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [July 8, 2022, 7:18am UTC](https://forum.ansible.com/t/need-help-for-xml-to-json-parsing-error-with-ansible-using-parse-xml/36815/3 "2022-07-08T07:18:01Z")

</div>

Perhaps, if you provide a clean piece of xml.

---

<div class="post-metadata">

**Author:** ![maulik\_patel](https://avatars.discourse-cdn.com/v4/letter/m/ec9cab/32.png) [@maulik\_patel](https://forum.ansible.com/u/maulik_patel)\
**Post date:** [July 10, 2022, 3:29pm UTC](https://forum.ansible.com/t/need-help-for-xml-to-json-parsing-error-with-ansible-using-parse-xml/36815/4 "2022-07-10T15:29:00Z")

</div>

**_i’m getting below error_**

**fatal: [localhost]: FAILED! =\> {“msg”: “unable to locate parse\_xml template: spec”}**

**_here is the xml data :_**

\<?xml version="1.0" encoding="UTF-8"?\>

\<vpn\_connection id=“vpn-008611c2097786810”\>  
\<customer\_gateway\_id\>cgw-0d4ee490353c847a6\</customer\_gateway\_id\>  
\<vpn\_gateway\_id\>vgw-02843421cc2ba3987\</vpn\_gateway\_id\>  
\<vpn\_connection\_type\>ipsec.1\</vpn\_connection\_type\>  
\<vpn\_connection\_attributes\>NoBGPVPNConnection\</vpn\_connection\_attributes\>  
\<ipsec\_tunnel\>  
\<customer\_gateway\>  
\<tunnel\_outside\_address\>  
\<ip\_address\>131.226.223.241\</ip\_address\>  
\</tunnel\_outside\_address\>  
\<tunnel\_inside\_address\>  
\<ip\_address\>169.254.77.10\</ip\_address\>  
\<network\_mask\>255.255.255.252\</network\_mask\>  
\<network\_cidr\>30\</network\_cidr\>  
\</tunnel\_inside\_address\>  
\</customer\_gateway\>  
\<vpn\_gateway\>  
\<tunnel\_outside\_address\>  
\<ip\_address\>52.71.191.154\</ip\_address\>  
\</tunnel\_outside\_address\>  
\<tunnel\_inside\_address\>  
\<ip\_address\>169.254.77.9\</ip\_address\>  
\<network\_mask\>255.255.255.252\</network\_mask\>  
\<network\_cidr\>30\</network\_cidr\>  
\</tunnel\_inside\_address\>  
\</vpn\_gateway\>  
  
\<authentication\_protocol\>sha1\</authentication\_protocol\>  
\<encryption\_protocol\>aes-128-cbc\</encryption\_protocol\>  
28800  
\<perfect\_forward\_secrecy\>group2\</perfect\_forward\_secrecy\>  
main  
\<pre\_shared\_key\>1i5R5wqKDUx2HGvlTAIcbupHPpyns.4H\</pre\_shared\_key\>  
  
  
esp  
\<authentication\_protocol\>hmac-sha1-96\</authentication\_protocol\>  
\<encryption\_protocol\>aes-128-cbc\</encryption\_protocol\>  
3600  
\<perfect\_forward\_secrecy\>group2\</perfect\_forward\_secrecy\>  
tunnel  
\<clear\_df\_bit\>true\</clear\_df\_bit\>  
\<fragmentation\_before\_encryption\>true\</fragmentation\_before\_encryption\>  
\<tcp\_mss\_adjustment\>1379\</tcp\_mss\_adjustment\>  
\<dead\_peer\_detection\>  
10  
3  
\</dead\_peer\_detection\>  
  
\</ipsec\_tunnel\>  
\<ipsec\_tunnel\>  
\<customer\_gateway\>  
\<tunnel\_outside\_address\>  
\<ip\_address\>131.226.223.241\</ip\_address\>  
\</tunnel\_outside\_address\>  
\<tunnel\_inside\_address\>  
\<ip\_address\>169.254.64.30\</ip\_address\>  
\<network\_mask\>255.255.255.252\</network\_mask\>  
\<network\_cidr\>30\</network\_cidr\>  
\</tunnel\_inside\_address\>  
\</customer\_gateway\>  
\<vpn\_gateway\>  
\<tunnel\_outside\_address\>  
\<ip\_address\>54.88.91.92\</ip\_address\>  
\</tunnel\_outside\_address\>  
\<tunnel\_inside\_address\>  
\<ip\_address\>169.254.64.29\</ip\_address\>  
\<network\_mask\>255.255.255.252\</network\_mask\>  
\<network\_cidr\>30\</network\_cidr\>  
\</tunnel\_inside\_address\>  
\</vpn\_gateway\>  
  
\<authentication\_protocol\>sha1\</authentication\_protocol\>  
\<encryption\_protocol\>aes-128-cbc\</encryption\_protocol\>  
28800  
\<perfect\_forward\_secrecy\>group2\</perfect\_forward\_secrecy\>  
main  
\<pre\_shared\_key\>NH\_yZv8oTv2FkCVS5OKbydIkMEItKWOO\</pre\_shared\_key\>  
  
  
esp  
\<authentication\_protocol\>hmac-sha1-96\</authentication\_protocol\>  
\<encryption\_protocol\>aes-128-cbc\</encryption\_protocol\>  
3600  
\<perfect\_forward\_secrecy\>group2\</perfect\_forward\_secrecy\>  
tunnel  
\<clear\_df\_bit\>true\</clear\_df\_bit\>  
\<fragmentation\_before\_encryption\>true\</fragmentation\_before\_encryption\>  
\<tcp\_mss\_adjustment\>1379\</tcp\_mss\_adjustment\>  
\<dead\_peer\_detection\>  
10  
3  
\</dead\_peer\_detection\>  
  
\</ipsec\_tunnel\>  
\</vpn\_connection\>
