Skip to main content

rs-xml2json

A high-performance XML-to-JSON converter written in Rust with Python bindings. It uses XSD schema definitions to produce correctly typed JSON output — integers, floats, booleans, and arrays are represented as their proper JSON types rather than treating everything as strings.

The primary focus for now is DATEX II data, but the library should be generic enough to support any XML-based data format.

Transparency: AI Usage

This library is mostly AI-generated and not fully reviewed, as I lack Rust skills. It's mostly tested against highly complex DATEX II schemas, and the results are convincing: it can handle the DATEX II schema variety, the outputs are correct, and it's fast enough to handle the enormous DATEX II XMLs. In both aspects, correctness and performance, it's better than any other library I found, even outside the Python ecosystem. Still, depending on your development preferences, you might not want to use this library.

Features

  • Schema-aware conversion: Uses XSD schemas to determine JSON types (string, integer, float, boolean) and array structures (via maxOccurs)
  • Correct array handling: Elements with maxOccurs="unbounded" are always emitted as JSON arrays, even when only a single element is present
  • Selectable JSON mapping conventions: pick the output shape that fits your downstream consumer
    • BadgerFish (default): attributes prefixed with @, mixed-content text under $
    • Parker: attributes dropped, simple elements collapse to their value, root element name stripped
    • Abdera: attributes nested under attributes, children nested under children
  • Streaming file I/O: Converts large XML files with buffered reading/writing (8 MB buffers)
  • Pre-parsed schemas: Parse an XSD once, reuse it across multiple conversions
  • XSD import/include support: Automatically resolves and parses referenced schema files
  • xsi:type support: Overrides element types dynamically based on xsi:type attributes
  • Python bindings via PyO3: Use directly from Python as a native module

Requirements

  • Rust >= 1.85 (edition 2024)
  • Python >= 3.8
  • maturin (for building the Python package)
  • uv (optional, for managing the Python environment)

Installation

Build and install the Python package

# Using maturin directly
maturin develop --release

# Or using uv
uv pip install -e .

This compiles the Rust code and installs the rs_xml2json Python module.

Build a wheel using Docker

A Docker-based build produces a self-contained .whl file for your local architecture without needing Rust or maturin installed on the host. By default it matches your system Python version (e.g. 3.12, 3.13, 3.14).

Two build variants are available:

Variant Dockerfile Wheel type Use case
debian (default) Dockerfile.debian manylinux Standard glibc-based distros (Ubuntu, Debian, Fedora, ...)
alpine Dockerfile.alpine musllinux Alpine-based / musl environments
# Build a manylinux wheel matching your system Python version (output goes to dist/)
make build

# Build a musllinux wheel instead
make build VARIANT=alpine

# Build for a specific Python version
make build PYTHON_VERSION=3.13
make build PYTHON_VERSION=3.14

# Combine both options
make build VARIANT=alpine PYTHON_VERSION=3.14

The resulting wheel will be in the dist/ directory. To build and install into a local .venv in one step:

make install

This creates the venv if it doesn't exist, builds the wheel, and installs it.

Build as a Rust library only

cargo build --release

Usage

Python API

from rs_xml2json import Convention, Schema, convert, convert_to_file, convert_bytes, \
    convert_with_schema, convert_to_file_with_schema, convert_bytes_with_schema

One-shot conversion (parses XSD each time)

# Convert XML file to JSON string (default convention: BadgerFish)
json_string = convert("data.xml", "schema.xsd")

# Pick a different convention
json_string = convert("data.xml", "schema.xsd", Convention.PARKER)
json_string = convert("data.xml", "schema.xsd", Convention.ABDERA)

# Convert XML file to JSON file (streaming, low memory)
convert_to_file("data.xml", "schema.xsd", "output.json")

# Convert raw bytes
json_string = convert_bytes(xml_bytes, xsd_bytes)
from rs_xml2json import Schema

# Parse the schema once
schema = Schema.from_file("schema.xsd")
# Or from bytes
schema = Schema.from_bytes(xsd_bytes)

# Reuse across conversions (convention argument is optional)
json_string = convert_with_schema("data.xml", schema)
convert_to_file_with_schema("data.xml", schema, "output.json", Convention.PARKER)
json_string = convert_bytes_with_schema(xml_bytes, schema)

CLI

# Default (BadgerFish) — prints JSON to stdout
rs-xml2json data.xml schema.xsd

# Write to a file
rs-xml2json data.xml schema.xsd output.json

# Choose a convention
rs-xml2json data.xml schema.xsd --convention parker
rs-xml2json data.xml schema.xsd output.json --convention abdera

Example

Given this XSD schema:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="catalog" type="CatalogType"/>
    <xs:complexType name="CatalogType">
        <xs:sequence>
            <xs:element name="name" type="xs:string"/>
            <xs:element name="item" type="ItemType" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:attribute name="version" type="xs:integer"/>
    </xs:complexType>
    <xs:complexType name="ItemType">
        <xs:sequence>
            <xs:element name="title" type="xs:string"/>
            <xs:element name="price" type="xs:decimal"/>
            <xs:element name="quantity" type="xs:integer"/>
            <xs:element name="available" type="xs:boolean"/>
        </xs:sequence>
        <xs:attribute name="id" type="xs:integer"/>
    </xs:complexType>
</xs:schema>

And this XML:

<catalog version="2">
    <name>Test Catalog</name>
    <item id="1">
        <title>Widget</title>
        <price>9.99</price>
        <quantity>100</quantity>
        <available>true</available>
    </item>
</catalog>

The output JSON will be:

{
  "catalog": {
    "@version": 2,
    "name": "Test Catalog",
    "item": [
      {
        "@id": 1,
        "title": "Widget",
        "price": 9.99,
        "quantity": 100,
        "available": true
      }
    ]
  }
}

Note that item is always an array (because the schema declares maxOccurs="unbounded"), and numeric/boolean values are properly typed.

JSON mapping conventions

rs-xml2json supports three named conventions. The default is BadgerFish. Schema-driven type coercion (XSD types → JSON scalars) and array detection (maxOccurs > 1 → always an array, even for a single item) apply to all three.

XML construct BadgerFish (default) Parker Abdera
Element with simple type Value (string, number, boolean) Value Value
Element with complex type Object Object Object with optional attributes and children
Element with maxOccurs > 1 Array Array Array
Attribute Key prefixed with @ Dropped Nested under attributes
Mixed content text $ key Dropped (Parker doesn't handle mixed) Stored under children when no child elements
Empty element null null null
Root element name Preserved as outer key Stripped (the root body is the top-level JSON) Preserved as outer key

Example output

For the XML shown above (<catalog version="2"> ... </catalog>):

BadgerFish (default):

{ "catalog": { "@version": 2, "name": "Test Catalog", "item": [ { "@id": 1, "title": "Widget", "price": 9.99, "quantity": 100, "available": true } ] } }

Parker (no attributes, root name dropped):

{ "name": "Test Catalog", "item": [ { "title": "Widget", "price": 9.99, "quantity": 100, "available": true } ] }

Abdera (attributes/children separated):

{ "catalog": { "attributes": { "version": 2 }, "children": { "name": "Test Catalog", "item": [ { "attributes": { "id": 1 }, "children": { "title": "Widget", "price": 9.99, "quantity": 100, "available": true } } ] } } }

Running tests

# Rust tests
cargo test

# Python CLI tests (requires the module to be installed first)
pip install -e ".[dev]"
maturin develop
pytest tests/test_cli.py -v

Project structure

├── Cargo.toml              # Rust package manifest
├── pyproject.toml           # Python package manifest (maturin)
├── src/
│   ├── lib.rs              # Python bindings (PyO3 module)
│   ├── error.rs            # Error types
│   ├── schema/
│   │   ├── mod.rs
│   │   ├── model.rs        # Schema data model (ElementDef, TypeDef, etc.)
│   │   ├── parser.rs       # XSD parser
│   │   └── type_map.rs     # XSD built-in type → JSON type mapping
│   └── converter/
│       ├── mod.rs
│       ├── convention.rs   # Convention enum (BadgerFish/Parker/Abdera)
│       └── walker.rs       # XML → JSON conversion engine
├── python/
│   └── rs_xml2json/
│       ├── __init__.py     # Python package re-exports
│       └── cli.py          # `rs-xml2json` command-line entry point
├── tests/
│   ├── integration_test.rs # Rust integration tests
│   ├── test_cli.py         # Python CLI integration tests (pytest)
│   ├── sample.xsd          # Test schema
│   └── sample.xml          # Test data
└── data/
    └── schema.xsd          # Example schema

License

See the project license file for details.

Metadata

Release files for rs-xml2json 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rs-xml2json 0.2.0
File Size Uploaded Provenance Actions
rs_xml2json-0.2.0.tar.gz 38.9 kB Without provenance Details for rs_xml2json-0.2.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for rs-xml2json 0.2.0
File Actions
rs_xml2json-0.2.0-cp38-abi3-win_amd64.whl CPython 3.8 abi3 Windows x86-64 Details for rs_xml2json-0.2.0-cp38-abi3-win_amd64.whl
rs_xml2json-0.2.0-cp38-abi3-win32.whl CPython 3.8 abi3 Windows x86-32 Details for rs_xml2json-0.2.0-cp38-abi3-win32.whl
rs_xml2json-0.2.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.8 abi3 Linux glibc 2.17+ x86-64 Details for rs_xml2json-0.2.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
rs_xml2json-0.2.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.8 abi3 Linux glibc 2.17+ ARM64 Details for rs_xml2json-0.2.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
rs_xml2json-0.2.0-cp38-abi3-manylinux_2_5_i686.manylinux1_i686.whl CPython 3.8 abi3 Linux glibc 2.5+ x86-32 Details for rs_xml2json-0.2.0-cp38-abi3-manylinux_2_5_i686.manylinux1_i686.whl
rs_xml2json-0.2.0-cp38-abi3-macosx_11_0_arm64.whl CPython 3.8 abi3 macOS 11.0+ ARM64 Details for rs_xml2json-0.2.0-cp38-abi3-macosx_11_0_arm64.whl

Total release size: 2.2 MB

Release files / rs_xml2json-0.2.0.tar.gz

Download URL rs_xml2json-0.2.0.tar.gz
Size 38.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f1adb487397851f723132bbce03de5caa7f02229cafbf42f191e1674a64b59bd
BLAKE2b-256 checksum
How to use checksums
b87dc7a10702e256ab1ed8cfdae3306e6f35ba97ff4cf843212b36b6775c528c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / rs_xml2json-0.2.0-cp38-abi3-win_amd64.whl

Download URL rs_xml2json-0.2.0-cp38-abi3-win_amd64.whl
Size 279.6 kB
Tags CPython 3.8 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
d6fd762730d3b0fc90c51054b7cb0d881bb5ad90f789230cbd6c5dbe43a50cbb
BLAKE2b-256 checksum
How to use checksums
55a072e8c97aef2527d3eed9a4b2d355d966bb2ba598c372035b11c58108a19c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / rs_xml2json-0.2.0-cp38-abi3-win32.whl

Download URL rs_xml2json-0.2.0-cp38-abi3-win32.whl
Size 271.0 kB
Tags CPython 3.8 Windows x86-32 abi3
SHA-256 checksum
How to use checksums
a9fc8e026dd2aa27ff6df505328cbe32a1e4ac941da6af6db0a878fd6cab2bcf
BLAKE2b-256 checksum
How to use checksums
c3586cfb5e80fb78638fbd1a1bd455e8a95399058c31239fd0427c480cd291da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / rs_xml2json-0.2.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL rs_xml2json-0.2.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 410.0 kB
Tags CPython 3.8 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
1568ee3713d94f1b3eb7ff59b9bd2ad252f30fc870cfce58cb4e4680ba90520c
BLAKE2b-256 checksum
How to use checksums
4ca4c26db2dd11baca3435c0c90d04c3cc25d6ddd15e351d3da488faea59bad9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / rs_xml2json-0.2.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL rs_xml2json-0.2.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 414.2 kB
Tags CPython 3.8 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
45a69f83526eea388e2b7ee4d05065353cea4c7417cd749d00306c28d65079af
BLAKE2b-256 checksum
How to use checksums
39f9387276587f5e87aabe7bf6f5d96f6f1ff7522c9b1ea2e6ce38186ef140c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / rs_xml2json-0.2.0-cp38-abi3-manylinux_2_5_i686.manylinux1_i686.whl

Download URL rs_xml2json-0.2.0-cp38-abi3-manylinux_2_5_i686.manylinux1_i686.whl
Size 450.7 kB
Tags CPython 3.8 Linux glibc 2.5+ x86-32 abi3
SHA-256 checksum
How to use checksums
ade5c30b6a1b2f8bacdfa5c0cb6f6e22d3020daaca4f8b6c6db52b28ecae5872
BLAKE2b-256 checksum
How to use checksums
640105ea6c61f3a8615e2a96eb9e37e3668b95b14e164ce2d9ff532358cf53c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / rs_xml2json-0.2.0-cp38-abi3-macosx_11_0_arm64.whl

Download URL rs_xml2json-0.2.0-cp38-abi3-macosx_11_0_arm64.whl
Size 375.3 kB
Tags CPython 3.8 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
89efeb8b29a73ef8a1c390a6173a7a09f329fce17acd5a6b3e81f6af27958194
BLAKE2b-256 checksum
How to use checksums
30b0ce7a59eae916de26dc74ae1d6e9c4dcc1cc3a250599c2a7e8d797b654e09
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for rs-xml2json 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

7 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page