Skip to main content

Simple TOON parser and converter for AI pipelines

Project description

mini-toon

Lightweight TOON parser and converter for LLM pipelines.

mini-toon is a small Python library designed to convert between TOON (Token-Oriented Object Notation) and JSON, making it easier to integrate outputs from LLMs, VLMs, OCR systems, and vision pipelines into structured data workflows.

The library focuses on simplicity, predictable structure, and data-oriented design.


Why mini-toon?

Large language models often struggle to generate valid JSON consistently. TOON provides a simpler, more predictable textual format that models can generate more reliably.

Example comparison:

JSON:

{
  "product": "rice",
  "quantity": 2
}

TOON:

product=rice; quantity=2

This format is:

  • easier for LLMs to generate
  • easier to parse
  • token-efficient
  • compatible with structured pipelines

Installation

pip install mini-toon

Features

  • Convert TOON → JSON
  • Convert JSON → TOON
  • Automatic type detection
  • Support for nested objects
  • Support for arrays
  • Schema validation
  • Designed for AI pipelines

Basic Example

from mini_toon import (
    toon_to_json,
    json_to_toon,
    validate_toon,
    ToonSchema
)

toon = """
product=rice; quantity=2
product=beans; quantity=3
"""

validate_toon(toon)

data = toon_to_json(toon)

print(data)

toon2 = json_to_toon(data)

print(toon2)

Output JSON:

{
  "items": [
    {
      "product": "rice",
      "quantity": 2
    },
    {
      "product": "beans",
      "quantity": 3
    }
  ]
}

Converted back to TOON:

product=rice; quantity=2
product=beans; quantity=3

Nested Objects

TOON supports nested objects using the . notation.

Example TOON:

product.name=White Rice; product.price=5.90; quantity=2

Converted JSON:

{
  "items": [
    {
      "product": {
        "name": "White Rice",
        "price": 5.9
      },
      "quantity": 2
    }
  ]
}

Arrays

Arrays are defined using the | separator.

Example TOON:

product=rice; quantity=2; tags=food|basic|market

Converted JSON:

{
  "items": [
    {
      "product": "rice",
      "quantity": 2,
      "tags": ["food", "basic", "market"]
    }
  ]
}

Schema Validation

You can enforce structure using ToonSchema.

Example:

schema = ToonSchema({

    "product": {
        "name": str,
        "price": float
    },

    "quantity": int,
    "tags": list
})

schema.validate(data["items"])

If the structure is invalid, an exception will be raised.


Example

Example TOON generated by an AI model:

product.name=White Rice; product.price=5.90; quantity=2; category=food; tags=basic|market
product.name=Black Beans; product.price=7.50; quantity=3; category=food; tags=grain|market
product.name=Dish Soap; product.price=3.40; quantity=1; category=cleaning; tags=home|kitchen

Converted JSON:

{
  "items": [
    {
      "product": {
        "name": "White Rice",
        "price": 5.9
      },
      "quantity": 2,
      "category": "food",
      "tags": ["basic", "market"]
    },
    {
      "product": {
        "name": "Black Beans",
        "price": 7.5
      },
      "quantity": 3,
      "category": "food",
      "tags": ["grain", "market"]
    },
    {
      "product": {
        "name": "Dish Soap",
        "price": 3.4
      },
      "quantity": 1,
      "category": "cleaning",
      "tags": ["home", "kitchen"]
    }
  ]
}

AI Pipeline Example

mini-toon works well inside AI pipelines.

Example TOON generated by an LLM:

product.name=White Rice; product.price=5.90; quantity=2; category=food
product.name=Black Beans; product.price=7.50; quantity=3; category=food

Converted JSON:

{
  "items": [
    {
      "product": {
        "name": "White Rice",
        "price": 5.9
      },
      "quantity": 2,
      "category": "food"
    },
    {
      "product": {
        "name": "Black Beans",
        "price": 7.5
      },
      "quantity": 3,
      "category": "food"
    }
  ]
}

Vision Detection Example

TOON also works well for outputs from vision models.

Example detection output:

object=person; box.x=120; box.y=230; box.width=50; box.height=100; confidence=0.91
object=dog; box.x=300; box.y=200; box.width=80; box.height=60; confidence=0.78

Converted JSON:

{
  "items": [
    {
      "object": "person",
      "box": {
        "x": 120,
        "y": 230,
        "width": 50,
        "height": 100
      },
      "confidence": 0.91
    },
    {
      "object": "dog",
      "box": {
        "x": 300,
        "y": 200,
        "width": 80,
        "height": 60
      },
      "confidence": 0.78
    }
  ]
}

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

mini_toon-0.1.1.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

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

mini_toon-0.1.1-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mini_toon-0.1.1.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for mini_toon-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f891d7c751e3a04d9bfc6c5ec1d8cdf2c2f370fe93f0d0dceb9b99ab186eb084
MD5 9292f8a212a596315cae2e0fee3930f6
BLAKE2b-256 24307da7e58683850b97ffa3fad7d2f8cbb4a7c3543fcf651f606075c7d54549

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mini_toon-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for mini_toon-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b4d501821e1e632f606e91ac30385f5d8a62726e3834efae6c35983b514402e8
MD5 5c4723281775c8b1f43b05ae30619717
BLAKE2b-256 03eeb492a81cdf68124f9b8f61d96339a099f6c99c0ba113392a995a2fc24fc8

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