toon-format/toon
🎒 Token-Oriented Object Notation (TOON) – compact, human-readable serialization of JSON data for LLM prompts. TypeScript SDK, CLI, benchmarks.
What it solves
TOON (Token-Oriented Object Notation) reduces the token cost of providing structured data to Large Language Models (LLMs) without sacrificing retrieval accuracy. It addresses the inefficiency of JSON, which spends significant tokens on repetitive structural characters like braces and quotes, especially when dealing with uniform arrays of objects.
How it works
TOON acts as a lossless translation layer for JSON data. It uses a combination of indentation-based structure (similar to YAML) and tabular forms to compress data. Key mechanisms include:
- Tabular Form: Declares a field list once in the header and then lists values in rows, similar to CSV, for uniform arrays of objects.
- Inline Form: Renders primitive arrays directly on the header line.
- Keyed Tabular: Handles objects containing uniform objects by marking them with a colon after the length (e.g.,
[2:]) and assigning a key to each row. - List Form: A fallback for non-uniform or mixed-type data using a dash-based list.
- Guardrails: Includes explicit lengths
[N]and field lists{fields}to help LLMs parse and validate data more reliably.
Who it’s for
Developers building LLM applications who need to pass large amounts of structured data into prompts and want to reduce API costs and token limits while maintaining high model comprehension.
Highlights
- Token Efficiency: Benchmarks show it can use up to 42.6% fewer tokens than JSON in some cases.
- Lossless Round-trips: Deterministically encodes the same data model as JSON.
- High Accuracy: Matches or exceeds JSON's retrieval accuracy across multiple models (Claude, Gemini, GPT, Grok).
- Multi-Language Support: Spec-driven implementations available across various languages.
- CLI Tool: Includes a command-line interface for quick conversion and token saving estimates.
Related
- Project
- Dispatch
- Project
- Project
- Project