if isinstance(o, lxml.objectify.NumberElement) or isinstance(o, lxml.
    objectify.FloatElement):
    return float(o)
if isinstance(o, lxml.objectify.ObjectifiedDataElement):
    return str(o)
if hasattr(o, '__dict__'):
    return o.__dict__
return json.JSONEncoder.default(self, o)
How to convert XML to JSON in Python?