xmljson

Convert XML into Python dictionary and JSON tree structures and back, across six conventions.

Library
PyPI
v0.2.1
125stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
36/100Needs Attention
Development Activity0
Maintenance0
Community72
Maturity60
Momentum12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
78/100Good
Architecture80
Code Quality74
Innovation72
Learning Curve85

xmljson is a Python library that converts XML documents into dictionary/JSON tree structures and back again. Unlike a single-format converter, it supports several well-known XML-to-JSON conventions so you can round-trip data in whichever representation your system expects.

It handles the fiddly parts of the mapping — attributes, text content, repeated elements, and empty nodes — according to the rules of each convention. The library builds on Python’s standard ElementTree API, so it slots into existing XML pipelines without new heavy dependencies.

What You Get

  • Bidirectional conversion between XML and Python dict/JSON tree structures
  • Six selectable conventions (BadgerFish, GData, Parker, Yahoo, Abdera, Cobra) for encoding attributes and text
  • Interoperability with Python’s built-in xml.etree.ElementTree and lxml element objects
  • Control over how attributes, text content, and repeated elements are represented
  • A small, dependency-light API usable inside existing XML processing code

Common Use Cases

  • Turning XML API responses into JSON-friendly Python dictionaries
  • Serializing Python data structures back into XML for legacy systems
  • Migrating data between XML- and JSON-based services using a fixed convention
  • Preserving attributes and text faithfully when a specific XML/JSON convention is required

Under The Hood

Architecture - The library centers on a XMLData base class that both parses and unparses, with one subclass per convention (BadgerFish, GData, Parker, Cobra, Abdera, Yahoo) overriding how attributes, text nodes, and children are named and nested. Conversion delegates to ElementTree: data() walks an element tree into nested dicts, while etree() walks a dict back into element objects. Tech Stack - Pure Python (96% of the codebase) with a small Makefile, targeting the standard-library xml.etree.ElementTree and optionally lxml. Packaging is setuptools-based and the runtime dependency footprint is minimal. Code Quality - The code is compact and organized around a clear class hierarchy, with a test suite covering each convention’s round-trip behavior. The project is stable but explicitly no longer actively maintained, as noted in its README. API Design - The public surface is deliberately tiny: import a convention instance (e.g. from xmljson import badgerfish as bf) and call bf.data(element) or bf.etree(dict). Swapping conventions is a one-line change, which keeps the learning curve low for anyone familiar with ElementTree.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search