import json
import xmltodict
with open("sample.xml", 'r') as f:
xmlString = f.read()
# print("XML input (sample.xml):")
# print(xmlString)
jsonString = json.dumps(xmltodict.parse(xmlString), indent=4)
# print("\nJSON output(output.json):")
# print(jsonString)
with open("sample.json", 'w') as f:
f.write(jsonString)