Created
August 4, 2022 09:14
-
-
Save baichen99/73b36acd4dcff47de0caf831fd1c217c to your computer and use it in GitHub Desktop.
convert xml to json
This file contains hidden or 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
# 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