xmltodict (full disclosure: I wrote it) can help you convert your XML to a dict+list+string structure, following this "standard". It is Expat-based, so it's very fast and doesn't need to load the whole XML tree in memory.

Once you have that data structure, you can serialize it to JSON:

import xmltodict, json

o = xmltodict.parse('<e> <a>text</a> <a>text</a> </e>')
json.dumps(o) # '{"e": {"a": ["text", "text"]}}'
Answer from Martin Blech on Stack Overflow
🌐
GitHub
github.com › eliask › xml2json
GitHub - eliask/xml2json: Convert XML to JSON with Python 3 and defusedxml or plain ElementTree
$ ./xml2json.py -h usage: xml2json.py [-h] [--unsafe] [infile] Convert an XML file to JSON. positional arguments: infile optional arguments: -h, --help show this help message and exit --unsafe do not use defusedxml: only for known-safe XML!
Starred by 12 users
Forked by 6 users
Languages   Python 100.0% | Python 100.0%
🌐
GitHub
github.com › rctatman › xml-to-json
GitHub - rctatman/xml-to-json: A little Python 3 utility script to convert .xml to .json · GitHub
A little Python 3 utility script to convert .xml to .json - rctatman/xml-to-json
Starred by 23 users
Forked by 13 users
Languages   Python
🌐
GitHub
github.com › halukyamaner › xml-to-json
GitHub - halukyamaner/xml-to-json: XML to JSON · GitHub
The XML to JSON is a Python utility designed to convert XML files into JSON format.
Author   halukyamaner
🌐
GitHub
github.com › Rajasekaran85 › Python-XML-to-JSON-file-Conversion
GitHub - Rajasekaran85/Python-XML-to-JSON-file-Conversion: Application convert the xml files into json files
Application convert the xml files into json files. Contribute to Rajasekaran85/Python-XML-to-JSON-file-Conversion development by creating an account on GitHub.
Author   Rajasekaran85
🌐
GitHub
github.com › kwaldenphd › json-xml-python
GitHub - kwaldenphd/json-xml-python: Working with JSON and XML files in Python (Elements of Computing II, S21, University of Notre Dame) · GitHub
Read the JSON data into Python and convert to a Python value. 41. Create your own small dictionary with data and convert to JSON string. Unlike HTML which allowed us to mark up and display information, XML is used for descriptive standards.
Author   kwaldenphd
🌐
GitHub
github.com › shanahanjrs › xmltojson
GitHub - shanahanjrs/xmltojson: Cli tool and Python module to convert XML to JSON
Python library and cli tool for converting XML to JSON
Starred by 12 users
Forked by 3 users
Languages   Python 100.0% | Python 100.0%
🌐
GitHub
github.com › hay › xml2json
GitHub - hay/xml2json: Python script converts XML to JSON or the other way around
May 2, 2019 - from xml2json import json2xml d = {'r': {'@p': 'p1', '#text': 't1', 'c': 't2'}} print(json2xml(d)) > b'<r p="p1">t1<c>t2</c></r>' ... This script was originally written by R.White, Rewritten to a command line utility by Hay Kranen with contributions ...
Starred by 465 users
Forked by 200 users
Languages   Python 100.0% | Python 100.0%
Find elsewhere
🌐
Plajjan
plajjan.github.io › 2020-01-29-convert-xml-to-json-and-yaml.html
Convert XML to JSON
January 29, 2020 - As there is no standardized ... of data in YAML has the same concepts as JSON, it is trivial to convert from JSON to YAML or vice versa with standard tools. Here is an example Python script that will do the conversion:...
🌐
GitHub
github.com › topics › xml-to-json
xml-to-json · GitHub Topics · GitHub
`json-to-xml-converter` is a simple Python library for converting JSON data to XML and vice versa.
🌐
GitHub
github.com › sanand0 › xmljson
GitHub - sanand0/xmljson: xmlsjon converts XML into Python dictionary structures (trees, like in JSON) and vice-versa.
This is a typical UNIX filter program: it reads file (or stdin), processes it in some way (convert XML to JSON in this case), then prints it to stdout (or file). Example with pipe: $ some-xml-producer | python -m xmljson | some-json-processor
Starred by 123 users
Forked by 33 users
Languages   Python 96.0% | Makefile 4.0% | Python 96.0% | Makefile 4.0%
🌐
GitHub
gist.github.com › smihica › 2792662
Xml to JSON parser-converter in Python. · GitHub
February 19, 2018 - Xml to JSON parser-converter in Python. GitHub Gist: instantly share code, notes, and snippets.
🌐
GitHub
gist.github.com › u1i › f9f83e1cabea57736aaaf52bdebca2ce
Python XML to JSON · GitHub
Python XML to JSON. GitHub Gist: instantly share code, notes, and snippets.
🌐
GitHub
github.com › blackrock › xml_to_json
GitHub - blackrock/xml_to_json: XML to JSON file conversion utility
Converts XML to valid JSON or JSONL Requires only two files to get started. Your XML file and the XSD schema file for that XML file. Multiprocessing enabled to parse XML files concurrently if the XML files are in the same format.
Starred by 18 users
Forked by 8 users
Languages   Python 100.0% | Python 100.0%
🌐
GitHub
github.com › rctatman › xml-to-json › blob › master › xmltojson.py
xml-to-json/xmltojson.py at master · rctatman/xml-to-json
A little Python 3 utility script to convert .xml to .json - xml-to-json/xmltojson.py at master · rctatman/xml-to-json
Author   rctatman
🌐
GitHub
github.com › davlee1972 › xml_to_json
GitHub - davlee1972/xml_to_json: xml to json parser
Converts XML to valid JSON or JSONL Requires only two files to get started. Your XML file and the XSD schema file for that XML file. Multiprocessing enabled to parse XML files concurrently if the XML files are in the same format.
Starred by 11 users
Forked by 2 users
Languages   Python 100.0% | Python 100.0%
🌐
GitHub
github.com › eurocontrol-swim › jsonize
GitHub - eurocontrol-swim/jsonize: A Python 3 library to convert XML documents to JSON
A Python 3 library to convert XML documents to JSON - eurocontrol-swim/jsonize
Author   eurocontrol-swim
🌐
GitHub
github.com › rparelius › lxml2json
GitHub - rparelius/lxml2json: python function to convert xml data into json format
lxml2json is a python package that converts XML elements into their JSON equivalent, and vice versa. There are many options to convert the data to a desired format:
Author   rparelius
🌐
GitHub
github.com › sinelaw › xml-to-json
GitHub - sinelaw/xml-to-json: Fast & easy command line tool for converting XML files to JSON · GitHub
Fast & easy library & command line tool for converting XML files to JSON.
Starred by 102 users
Forked by 21 users
Languages   Haskell 88.8% | Shell 6.7% | JavaScript 4.5%