I need to convert XML to json without root in python. Here is an example of XML
<?xml version="1.0" encoding="UTF-8"?>
<root>
<row>
<Member_ID>926494</Member_ID>
<First_Name>Corissa</First_Name>
<Last_Name>Aguiler</Last_Name>
<Gender>F</Gender>
<Age>39</Age>
<Height>5,3</Height>
<Weight>130</Weight>
<Hours_Sleep>8</Hours_Sleep>
<Calories_Consumed>2501</Calories_Consumed>
<Exercise_Calories_Burned>990</Exercise_Calories_Burned>
<Date>9/11/2017</Date>
</row>
</root>
I need to convert into JSON in the following format
{
"Member_ID": 926494,
"First_Name": "Corissa",
"Last_Name": "Aguiler",
"Gender": "F",
"Age": 39,
"Height": "5,3",
"Weight": 130,
"Hours_Sleep": 8,
"Calories_Consumed": 2501,
"Exercise_Calories_Burned": 990,
"Date": "9/11/2017"
},
I am trying to use the parker convention from xmljson library but all the examples I'm finding are using string as input. I can't seem to figure out how to pass the actual .xml file instead of a string
For example:
from xmljson import parker, Parker
from xml.etree.ElementTree import fromstring
from json import dumps
dumps(parker.data(fromstring('<x><a>1</a><b>2</b></x>')))
'{"a": 1, "b": 2}'