if len(items) == 0:
    return text
return {k: (v[0] if len(v) == 1 else v) for k, v in list(items.items())}
if __name__ == '__main__':
    json_data = parse_xml('large.xml')
print(json.dumps(json_data, indent=2))
Python - Convert Very Large (6.4GB) XML files to JSON