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 LLMs without sacrificing retrieval accuracy. It addresses the verbosity of standard JSON and YAML, which can be expensive and inefficient when dealing with large datasets in a model's context window.
How it works
TOON acts as a lossless translation layer for JSON. It uses a combination of indentation-based structure (like YAML) and tabular forms (like CSV) to represent data more compactly. It automatically selects the most efficient form based on the data's shape:
- Inline Form: Represents primitive arrays on a single line.
- Tabular Form: Declares a field list once in the header and streams row values line-by-line for uniform arrays of objects.
- Keyed Tabular: Used for objects containing uniform objects (e.g., config maps), where each row carries its own key.
- List Form: A fallback for non-uniform or mixed-type data.
It also includes explicit length markers [N] and field lists {fields} to provide the LLM with clear structural guardrails.
Who itโs for
Developers building LLM applications that need to pass large amounts of structured data (such as records, logs, or configurations) into prompts, specifically those looking to reduce API costs and token usage while maintaining high model performance.
Highlights
- Token Efficiency: Benchmarks show it can use up to 42.6% fewer tokens than standard JSON while maintaining or improving retrieval accuracy.
- Lossless Round-trips: Deterministic encoding of the same data model as JSON.
- LLM-Friendly Guardrails: Explicit lengths and field lists help models parse and validate data more reliably.
- Multi-Language Support: Spec-driven implementations available in TypeScript, Python, Go, Rust, and .NET.