Skip to main content

DATEX2-XML2JSON (Proof of Concept)

This tool provides a PoC converter to convert DATEXII XML to JSON or GeoParquet format.

As output format, the following formats are supported

  • DATEXII v3.7 JSON
  • a custom DATEXII 3.7 (we call it "DATEXII v3.7 JSON Lite") variation which deviates from official schema but is easier to process (see below)
  • a (mostly) flattened GeoJSON
  • a geoparquet format derived from above mostly flat GeoJSON format.

Curently, supported DATEXII input is limited to SituationPublications in DATEXII v2.x.

Note: This tool uses XML schemas to derive cardinality and type information for the JSON conversion to JSON. Custom extensions might require supplying specific schemas to support this conversion.

Preliminaries

This project requires Python >= 3.12 and uv installed.

Install the needed dependencies via

$ uv sync

Usage

Below, you find a couple of sample formats to generate different output formats.

If you encounter issues, i.e. an invalid DATEXII v3.7, you might consult the troubleshooting guide. If this is does not help, please open an issue and supply a minimal DATEXII XML sample and your command to reproduce the issue.

In case you fixed an error or want to contribute, please create an issue as well and feel free to send a PR, thanks.

DATEXII v3.7

To convert a DATEXII v2.2 XML publication to DATEXII v3.7, use the following command. It will create out/situation_publication.json and will validate it after generation.

uv run python -m datex2_xml2json.transformer -f datex2_3_7_json -V situation_publication.xml

DATEXII (mostly) flat GeoJSON

To convert a DATEXII v2.2 XML situation publication to a (mostly) flat GeoJSON file, use the following command. It will create out/situation_publication.geojson. Note that this is a lossy conversion which retains a subset of all possible DATEXII properties. For details which elements are picked, see jsonata_transformer.py.

uv run python -m datex2_xml2json.transformer -f geojson situation_publication.xml

DATEXII Geoparquet

To convert a DATEXII v2.2 XML publication to a Geoparquet file, use the following command. It will create out/situation_publication.geoparquet.

Note that all timestamp properties are exported as UTC timestamps, their original offsets applied.

uv run python -m datex2_xml2json.transformer -f geoparquet situation_publication.xml

To merge multiple geoparquet files with identical schema into a common one, you may use

uv run python -m datex2_xml2json.merge <directory containing parquet files> -o merged.parquet

DATEXII v3.7 JSON Lite

To convert a DATEXII v2.2 XML publication to a DATEXII v3.7 JSON "Lite" format, use the following command. It will create out/situation_publication.lite.json:

uv run python -m datex2_xml2json.transformer -f datex2_3_7_json_lite situation_publication.xml

Warning: the JSON resulting from this conversion does not comply with DATEXII JSON Schema.

Some differences:

  • this format does not use the DATEXII part 15 xsi-type dependant wrapper objects, but keeps the xsi:type attribute as property type.
  • it does not wrap text objects in value wrappers
  • we try to create a geoJsonGeometry location from gmlLineString locations. For locationContainedInGroup, we collect all linestrings in an MultiLineString object

DATEXII v2.2 RAW JSON

To convert a DATEXII v2.2 XML publication to an intermediate JSON which just converts the XML to a JSON file using the DATEXII v2.2 schema, use the following command. It will create out/situation_publication.raw.json.

uv run python -m datex2_xml2json.transformer -f raw situation_publication.xml

WAZE CIFS Format

To convert a DATEXII v2.2 XML situation publication to WAZE CIFS Format, use the following command. It will create out/situation_publication.cifs.json.

uv run python -m datex2_xml2json.transformer -f cifs situation_publication.xml

To validate the generated json against the CIFS schema, supply the -v switch.

uv run python -m datex2_xml2json.transformer -f cifs -V situation_publication.xml

Note: currently, this converter does not handle validityPeriods. I.E. recurring events at specific days/hours are not yet mapped to CIFS schedule.

Generating multiple output formats in one run

To convert a DATEXII v2.2 XML situation publication to WAZE CIFS Format, GeoJSON and Geoparquet in one run (which avoids repeated parsing/transformation steps), run the following command (without explicitly specifing a format parameter): It will create out/situation_publication.datex2.raw.json, out/situation_publication.datex2.lite.json, out/situation_publication.datex2.geojson, out/situation_publication.datex2.parquet andout/situation_publication.cifs.json.

uv run python -m datex2_xml2json.transformer situation_publication.xml

Development

This section provides information how to develop with this lib.

How the transformation works

This converter runs multiple conversion steps which create intermediate formats which are used as homogenized input for subsequent transformation steps.

The following chart describes this conversion chain:

flowchart TD
  DATEX2v2.2XML -- "load_as_json_using_schema" --> DATEX2v2.2JSON
  DATEX2v2.2JSON -- RulesTransformer\nwith LiteJSON rules --> DATEX2v3.7LiteJSON
  DATEX2v2.2JSON -- RulesTransformer\nwith v3.7 JSON rules --> DATEX2v3.7JSON
  DATEX2MostlyFlatGeoJSON -- CifsTransformer --> WazeCIFS 
  DATEX2v3.7LiteJSON -- JsonataTransformer\nGeoJSONGeometryTransformer --> DATEX2MostlyFlatGeoJSON
  DATEX2MostlyFlatGeoJSON -- GeoparquetRenderer --> DATEX2GeoParquet

Working with JSONata

JSONata is a powerful transformation language to define mappings between different JSON formats. Easiest way to learn about it, is starting with an existing transformation using the JSONata.org online editor.

E.g. you could start with the following to example transformations (which might not exactly reflect the latest code version of this project):

  • https://try.jsonata.org/Gk5r-kLek: Mapping DATEX3.7LiteJSON to DATEX2MostlyFlatGeoJSON (Current JSONata expression is in src/datex2_xml2json/transform/jsonata_transformer.py)
  • https://try.jsonata.org/QEnqmItyF: Mapping DATEX2MostlyFlatGeoJSON to (mostly) WAZE CIFS (Current JSONata expression is in src/datex2_xml2json/transform/cifs_transformer.py)

Running tests

You can execute the test suite via

uv sync --group dev
uv run pytest

Metadata

Release files for datex2-xml2json 0.0.3

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

Source distribution (sdist)

Source distribution for datex2-xml2json 0.0.3
File Size Uploaded Provenance Actions
datex2_xml2json-0.0.3.tar.gz 524.5 kB Without provenance Details for datex2_xml2json-0.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for datex2-xml2json 0.0.3
File Interpreter ABI Platform Actions
datex2_xml2json-0.0.3-py3-none-any.whl Python 3 none any Details for datex2_xml2json-0.0.3-py3-none-any.whl

Total release size: 1.1 MB

Release files / datex2_xml2json-0.0.3.tar.gz

Download URL datex2_xml2json-0.0.3.tar.gz
Size 524.5 kB
Tags Source
SHA-256 checksum
How to use checksums
265bcdca65aa44d7cc2586d50475b6409043dafadaeb4c1903ca9225c7746345
BLAKE2b-256 checksum
How to use checksums
c9397ddedcfd8549affabd4e80d6a48141df9821b05e11fce2117e9da49251a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / datex2_xml2json-0.0.3-py3-none-any.whl

Download URL datex2_xml2json-0.0.3-py3-none-any.whl
Size 547.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d719e6d4acf29a696c7e0f86db2a577cc29f0941cbcae766b9468b7d0c6aa7e4
BLAKE2b-256 checksum
How to use checksums
57faf11096d054bceb96384a21f2ed2733d71dcc352ae8a258b318599abe5c30
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for datex2-xml2json 0.0.3

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.

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