Skip to content

Customer Service: +49 711 50438689

Free shipping from €50 (DE)

code

Convert XML to JSON with Python

22.07.2022 0 Comments

If you want to convert an XML document into a JSON document in Python, you can use the functions of the xmltodict module by first feeding your XML file into a Python dictionary and then converting this dictionary with the Python json module (import json) converts and saves. This can then look like this:

 import xmltodict , json

with open ( 'your-xml-file.xml' , 'r' , encoding = 'utf-8' , errors = 'ignore' ) as myfile:
obj = xmltodict.parse(myfile.read())
myfile.close()
json_data = json.dumps(obj , indent = 4 )

f = open ( "your-created-json-file.json" , "w" )
f.write(json_data)
f.close()

Leave a comment

Please note, comments need to be approved before they are published.

Thanks for subscribing!

This email has been registered!

Shop the look

Choose Options

Edit Option
this is just a warning
Login