Last active
March 25, 2021 10:27
-
-
Save luisramirezdev/6247d97e3dc66d8ca5fe6fccff67ea7b to your computer and use it in GitHub Desktop.
XML to JSON|-|{"files":{"xmltojson.py":{"env":"plain"}},"tag":"JSON"}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment