Skip to content

Instantly share code, notes, and snippets.

@iljavs
Created February 25, 2024 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iljavs/cd047cdc9553ccffe4675f9de71636ab to your computer and use it in GitHub Desktop.
Save iljavs/cd047cdc9553ccffe4675f9de71636ab to your computer and use it in GitHub Desktop.
convert xml to json
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