Skip to main content

Compact Data Exchange Format -- universal binary interchange for JSON, YAML, XML, and TOML

Project description

CDXF — Compact Data Exchange Format

A universal binary interchange format whose information model is a provable superset of JSON, YAML, XML, and TOML, enabling lossless round-trip encoding of documents from any of these format families.

Status

Alpha. The specification and reference implementation are functional with 408 tests passing. All four format bridges (JSON, YAML, XML, TOML) are complete with full round-trip fidelity verified on a 43-file benchmark corpus.

Motivation

Every existing binary serialization format is anchored to a single text format's information model. CBOR and MessagePack encode the JSON data model. EXI and Fast Infoset encode the XML Information Set. Nothing encodes YAML's graph-structured representation or TOML's typed configuration model. And critically, no binary format preserves all of them through a single unified information model.

CDXF fills that gap.

What CDXF preserves that others lose

Empirically verified via automated tests (EXP-001 Feature Preservation Matrix):

Construct CDXF CBOR MsgPack BSON Ion
Map key order
Non-string map keys
Comments
Anchors/Aliases (graph)
Merge keys
Multi-document streams
XML elements/attributes
XML namespaces
XML mixed content
Processing instructions
Typed timestamps
Typed date/time (local)
Total 12/12 3/12 1/12 2/12 0/12

Installation

pip install cdxf

CLI Usage

# Encode a JSON file to CDXF binary
cdxf encode config.json                   # -> config.cdxf

# Decode back to text (auto-detects source format)
cdxf decode config.cdxf                   # -> config.json

# Convert between formats via CDXF
cdxf convert data.yaml --to json          # -> data.json
cdxf convert config.json --to toml        # -> config.toml

# Inspect a file
cdxf info config.json
# File:          config.json
# Type:          JSON text
# Text size:     2,946 bytes
# CDXF size:     2,001 bytes
# Ratio:         0.679
# Node counts:   {'Map': 9, 'Scalar': 114, 'Sequence': 2}

Python API

from cdxf.bridges import from_json, to_json, from_yaml, to_yaml
from cdxf.bridges import from_xml, to_xml, from_toml, to_toml
from cdxf.codec import encode, decode

# JSON round-trip through binary
stream = from_json('{"name": "Alice", "age": 30}')
binary = encode(stream)          # compact CBOR-based binary
restored = decode(binary)
print(to_json(restored))         # '{"name": "Alice", "age": 30}'

# Cross-format conversion: YAML → CDXF → JSON
stream = from_yaml("name: Alice\nage: 30\n")
print(to_json(stream))           # '{"name": "Alice", "age": 30}'

# YAML with anchors and comments — preserved through binary
yaml_doc = """
# Server defaults
defaults: &defaults
  timeout: 30
  retries: 3
production:
  <<: *defaults
  timeout: 60
"""
stream = from_yaml(yaml_doc)
binary = encode(stream)          # anchors, comments, merge keys preserved
restored = decode(binary)
print(to_yaml(restored))         # anchors and comments survive

# XML with namespaces and mixed content
xml_doc = '<p xmlns="http://www.w3.org/1999/xhtml">Hello <b>world</b>!</p>'
stream = from_xml(xml_doc)
binary = encode(stream)          # namespaces, mixed content preserved
restored = decode(binary)
print(to_xml(restored))          # faithful reconstruction

Size Efficiency

Median CDXF/text size ratios on a 43-file benchmark corpus:

Format Median Interpretation
JSON 0.66 34% smaller than text
TOML 0.75 25% smaller
YAML 0.82 18% smaller
XML 1.26 26% larger (namespace URIs stored explicitly)

For JSON data, CDXF shorthand mode produces byte-identical output to standard CBOR — zero overhead.

Documentation

License

MIT. See LICENSE.

Author

Muntaser Syed (@jemsbhai) — Florida Institute of Technology

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cdxf-0.1.1.tar.gz (50.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cdxf-0.1.1-py3-none-any.whl (26.4 kB view details)

Uploaded Python 3

File details

Details for the file cdxf-0.1.1.tar.gz.

File metadata

  • Download URL: cdxf-0.1.1.tar.gz
  • Upload date:
  • Size: 50.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for cdxf-0.1.1.tar.gz
Algorithm Hash digest
SHA256 55aa59c9ebe4d0e4b628cd4b004c1cd1f9121659eb36d169bcac5cd38a020c19
MD5 0d25e07ae4a5525b610b9cc54a8a1b0c
BLAKE2b-256 4a9c7ff0a312a9b6b75c0831a70f20286a16ffbf6d81e0cba5fced0771f1b1cf

See more details on using hashes here.

File details

Details for the file cdxf-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: cdxf-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 26.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for cdxf-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7a91899a06a8aa7fc00b3eaf48f6e614a2e93821acc1970328f97920ffdb709d
MD5 b222fe61106013d63d2785e5775b93ec
BLAKE2b-256 36fe578b6c92d6737089022b01e7d60de58ddd2ac7121716b77f1c1152446705

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page