Skip to main content

Token-Oriented Object Notation - Compact JSON serialization for LLM prompts

Project description

TOON Converter

Token-Oriented Object Notation - A compact, human-readable format for serializing JSON data in LLM prompts.

Python 3.8+ License: MIT

🎯 Features

  • ✅ Bidirectional JSON ↔ TOON conversion
  • ✅ 30-50% token reduction vs standard JSON
  • ✅ Multi-level nested structure support
  • ✅ Comprehensive validation & error reporting
  • ✅ CLI tool for file processing
  • ✅ REST API for integration
  • ✅ Production-ready library

📦 Installation

pip install toon-converter

🚀 Quick Start

Python Library

from toon_converter import json_to_toon, toon_to_json

# JSON to TOON
data = {"name": "Alice", "age": 30, "roles": ["admin", "editor"]}
toon = json_to_toon(data)
print(toon)
# Output:
# name: Alice
# age: 30
# roles:
#   admin
#   editor

# TOON to JSON
json_data = toon_to_json(toon)

CLI Usage

# Convert JSON to TOON
toon convert input.json -o output.toon

# Convert TOON to JSON
toon convert input.toon -o output.json

# Validate files
toon validate input.toon

API Usage

# Start server
uvicorn api.app:app --reload

# Convert via API
curl -X POST http://localhost:8000/convert/json-to-toon \
  -H "Content-Type: application/json" \
  -d '{"name": "Alice", "age": 30}'

📖 Format Specification

TOON Format Rules

  1. Objects: Key-value pairs with : separator
  2. Arrays: Indented list items (no brackets)
  3. Nesting: Indentation-based structure
  4. Types: Automatic inference (string, number, boolean, null)

Examples

Simple Object

name: Alice
age: 30
active: true

Nested Structure

user:
  profile:
    name: Alice
    settings:
      theme: dark
      notifications: true

Arrays

items:
  apple
  banana
  orange
numbers:
  1
  2
  3

Mixed Types

config:
  name: MyApp
  version: 1.0
  enabled: true
  maxRetries: 3
  timeout: null
  features:
    auth
    logging

🏗️ Project Structure

toon-converter/
├── src/toon_converter/    # Core library
├── tests/                 # Test suite
├── cli/                   # CLI tool
├── api/                   # REST API
├── docs/                  # Documentation
└── examples/              # Usage examples

🧪 Testing

# Run all tests
pytest

# Run with coverage
pytest --cov=toon_converter --cov-report=html

# Run specific test
pytest tests/test_json_to_toon.py

📚 Documentation

🤝 Contributing

Contributions welcome! Please read our contributing guidelines.

📄 License

MIT License - see LICENSE file for details.

🔗 Links

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

toon_converter-0.1.0.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

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

toon_converter-0.1.0-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file toon_converter-0.1.0.tar.gz.

File metadata

  • Download URL: toon_converter-0.1.0.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for toon_converter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4afe3b982ddbb9875a066fb32b25eb7fa335f3b25e0a53c7395b7fca9efa2756
MD5 6b35f7f68e1a8d914689a363968a006d
BLAKE2b-256 5ad186cc7e3f9639b84babc40c8fb83dffe7c8be8137e129763361f7013b0757

See more details on using hashes here.

File details

Details for the file toon_converter-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: toon_converter-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for toon_converter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 afa9c96f7876e1dbe2e4726847700df08867af7339d2ac124d5a124aaf8d00e7
MD5 e3702864d2cf4094f85c4a83a3529288
BLAKE2b-256 4b4ccfafbcd393bedfd3c4062085af3469b497c9d91c9b0cbb151d60908587ae

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