I'd suggest using xmljson lib, and code something like this:
from collections import OrderedDictfrom xmljson import BadgerFishfrom json import dumpsdef xml_to_json(xml_string): bf = BadgerFish(dict_type=OrderedDict) return dumps(bf.data(fromstring(xml_string)))