Need to convert data in xml to json using python

I need to convert xml data to json format.
I am using django for backend, and I’m not really comfortable parsing data from xml, so I thought about converting data in json and then parsing it.
The xml data format is as shown below:

<?xml version='1.0' encoding='ASCII'?>
<add>
...
 <doc>
  <field name="id">1</field>
  <field name="title1">subtitle1</field>
  <field name="title2">subtitle2</field>
 </doc>
...
</add>

I need to convert format into json using python.

Also, if there is any better way to do it, please let me know.

I tried converting using online converters but the json data is not accurate. I’m getting the values but not the keys and some converters are throwing error.

Read more here: Source link