ToonEx

Hex.pmDocumentationLicense: MIT

High-performance TOON (Token-Oriented Object Notation) encoder/decoder for Elixir with Phoenix Channels support.

TOON is a compact, human-readable data format optimized for LLM token efficiency.

Features

Installation

Add toon_ex to your dependencies in mix.exs:

def deps do
  [
    {:toon_ex, "~> 0.5"}
  ]
end

Quick Start

Encoding

# Simple object
ToonEx.encode!(%{"name" => "Alice", "age" => 30})
# => "age: 30\nname: Alice"

# Nested object
ToonEx.encode!(%{"user" => %{"name" => "Bob"}})
# => "user:\n  name: Bob"

# Arrays
ToonEx.encode!(%{"tags" => ["elixir", "toon"]})
# => "tags[2]: elixir,toon"

Decoding

ToonEx.decode!("name: Alice\nage: 30")
# => %{"name" => "Alice", "age" => 30}

ToonEx.decode!("tags[2]: a,b")
# => %{"tags" => ["a", "b"]}

# Atom keys
ToonEx.decode!("name: Alice", keys: :atoms)
# => %{name: "Alice"}

Phoenix Channels

# In your endpoint configuration
config :my_app, MyApp.Endpoint,
  websocket: [
    serializer: [{ToonEx.Phoenix.Serializer, "~> 1.0"}]
  ]

See ToonEx.Phoenix.Serializer for details.

API Reference

Core Functions

Encoding Options

Decoding Options

Modules

Specification

This implementation follows TOON Specification v1.3 and is tested against official fixtures.

Testing

# Run all tests
mix test

# Run with coverage
mix coveralls

# Code quality checks
mix quality

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

License

MIT License - see LICENSE.