Stop Wasting Tokens: A Smarter Alternative to JSON for LLM Pipelines
Summary
TOON (Token-Oriented Object Notation) is a new serialization format designed to reduce token overhead when feeding structured data into large language model (LLM) pipelines. Unlike JSON, which repeats field names and structural elements like braces and commas for every object in an array, TOON declares fields once and then streams row values in a compact, tabular form. This approach significantly reduces the number of tokens required for uniform arrays of objects, such as support tickets or product rows, making LLM prompts more efficient. The format is lossless, allowing conversion from JSON to TOON and back without data loss. While JSON remains suitable for APIs, storage, and application logic, TOON is optimized for LLM input, particularly when dealing with repetitive structured records. The article demonstrates how to install the TOON CLI, convert JSON files, and integrate TOON into LLM prompts, while also advising against using it for model outputs due to JSON's superior tooling and schema enforcement capabilities.
Key takeaway
For AI Engineers and MLOps Engineers optimizing LLM pipeline costs, you should evaluate TOON for structured data inputs. If your prompts frequently include large, repetitive JSON arrays like retrieved records or tool outputs, converting them to TOON can significantly reduce token usage and potentially improve model comprehension. However, continue using JSON for model outputs where robust parsing and schema enforcement are critical for downstream systems.
Key insights
TOON reduces LLM token waste by compactly representing repetitive structured data, optimizing prompt efficiency.
Principles
- Minimize token repetition in LLM inputs.
- Preserve JSON data model with fewer tokens.
- Optimize for uniform arrays of objects.
Method
Convert JSON to TOON for LLM input using the TOON CLI, declaring object shapes once and streaming values, then revert to JSON for machine-parseable outputs.
In practice
- Use TOON for large, structured LLM prompt contexts.
- Keep JSON for application logic and API outputs.
- Benchmark TOON's token savings and quality.
Topics
- TOON Format
- LLM Pipelines
- Token Optimization
- Structured Data Input
- JSON Serialization
Best for: AI Engineer, Machine Learning Engineer, MLOps Engineer
Related on AIssential
Editorial summary, takeaway, and curation by AIssential. Original article published by KDnuggets.