Skip to content

Instantly share code, notes, and snippets.

@luisramirezdev
Last active March 25, 2021 10:27
Show Gist options
  • Save luisramirezdev/6247d97e3dc66d8ca5fe6fccff67ea7b to your computer and use it in GitHub Desktop.
Save luisramirezdev/6247d97e3dc66d8ca5fe6fccff67ea7b to your computer and use it in GitHub Desktop.
XML to JSON|-|{"files":{"xmltojson.py":{"env":"plain"}},"tag":"JSON"}
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