Skip to content

Instantly share code, notes, and snippets.

@baichen99
Created August 4, 2022 09:14
Show Gist options
  • Save baichen99/73b36acd4dcff47de0caf831fd1c217c to your computer and use it in GitHub Desktop.
Save baichen99/73b36acd4dcff47de0caf831fd1c217c to your computer and use it in GitHub Desktop.
convert xml to json
# pip install xmltodict
import xmltodict
import json
def xml_to_json(xml_path, out_path):
with open(xml_path, 'r', encoding='utf-8') as xml_file:
data_dict = xmltodict.parse(xml_file.read())
with open(out_path, 'w') as f:
json.dump(data_dict, f, ensure_ascii=False, indent=4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment