Created
February 25, 2024 22:17
-
-
Save iljavs/cd047cdc9553ccffe4675f9de71636ab to your computer and use it in GitHub Desktop.
convert xml to 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 xmltodict | |
import json | |
import sys | |
xmlfile = sys.argv[1] | |
jsonfile = xmlfile.replace('.xml', '.json') | |
with open(xmlfile, 'r') as file: | |
xml_string = file.read() | |
dict_data = xmltodict.parse(xml_string) | |
json_data = json.dumps(dict_data, indent=4) | |
with open(jsonfile, 'w') as json_file: | |
json_file.write(json_data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment