Everything you need to know about using TOON with Large Language Models
TOON (Token-Oriented Object Notation) is a compact, human-readable encoding of the JSON data model specifically designed for Large Language Models. It was created to address the token inefficiency of standard JSON when used in LLM applications.
Traditional JSON, while excellent for APIs and human readability, is verbose with its braces, quotes, and repeated keys. Every token costs money in LLM applications, and context windows have limits. TOON reduces token usage by 30-60% on uniform datasets while maintaining full JSON compatibility and human readability.
No, TOON is not a replacement for JSON. It's a specialized encoding format optimized for a specific use case: passing structured data to Large Language Models.
Think of it as a translation layer: you continue using JSON in your application code, APIs, and storage. When you need to pass data to an LLM, you encode it as TOON to save tokens. When the LLM returns TOON data, you decode it back to JSON.
Token savings depend heavily on your data structure:
Deeply nested structures, highly irregular data, or objects with mostly unique field sets may not benefit from TOON and could even use more tokens than compact JSON.
LLMs were not trained specifically on TOON, but they generally understand it well because:
Benchmark results show LLMs achieve 73.9% accuracy on TOON data retrieval tasks compared to 69.7% for JSON, suggesting models may actually parse TOON more reliably than JSON in some contexts.
users[N]{`{id,name,role}`}:) to help the model follow the correct structure.
Install the official NPM package:
npm install @toon-format/toon
Converting JSON to TOON:
import { encode } from "@toon-format/toon"; const data = { users: [ { id: 1, name: "Alice", role: "admin" }, { id: 2, name: "Bob", role: "user" } ] }; const toonString = encode(data); console.log(toonString);
Converting TOON back to JSON:
import { decode } from "@toon-format/toon"; const toonString = ` users[2]{id,name,role}: 1,Alice,admin 2,Bob,user `; const jsonObject = decode(toonString);
Install the Python package:
pip install python-toon
Encoding JSON to TOON:
from toon import encode # A channel object channel = {"name": "tapaScript", "age": 2, "type": "education"} toon_output = encode(channel) print(toon_output)
Decoding TOON back to JSON:
from toon import decode toon_string = """ name: tapaScript age: 2 type: education """ python_struct = decode(toon_string) print(python_struct)
No, TOON is typically generated programmatically. Most TOON data will be:
While TOON is human-readable and can be written manually, the main workflow is to convert your existing JSON data to TOON programmatically, especially when preparing prompts for LLMs.
TOON currently has official implementations for:
@toon-format/toon (NPM)
python-toon (PyPI)
The format is designed to work well with Go, Rust, and other languages, with more implementations expected as the format gains adoption.
TOON is ideal for:
Passing structured data to GPT, Claude, Gemini, or other language models where token efficiency matters
Datasets with many records sharing the same structure (users, products, transactions, logs)
Applications where reducing token costs is critical (high-volume API calls, training data preparation)
When you need to fit more data into limited context windows
TOON is being explored for:
Absolutely! A hybrid approach often works best:
This gives you the best of both worlds: JSON's universal compatibility for regular use, and TOON's efficiency when communicating with AI models.
JSON might be better when:
Complex hierarchical structures with many levels of nesting may not benefit from TOON
Objects with varying fields or highly inconsistent structures across array items
Standard web APIs, databases, configuration files, or any non-LLM use case
Applications requiring type enforcement, validation, or schema definitions (use JSON Schema instead)
Yes, in certain cases TOON can be less efficient than compact JSON. This typically happens with:
TOON is NOT a replacement for JSON in traditional web/API contexts:
TOON.parse())TOON is specifically designed for LLM communication, not as a general-purpose data format. You'll need to convert between JSON and TOON programmatically when interfacing with AI models.
TOON is in active development with specification v2.0 released. Consider these factors:
Many teams are successfully using TOON in production for AI workflows, but it's wise to test thoroughly and maintain JSON as a fallback option.
TOON is gaining traction in the AI developer community with potential for:
"Just as JSON has been a standard for the Web's data exchange, TOON may soon be standardized for AI data interchange."
TOON is an open-source project with an active community:
Here's a quick start guide:
Use our JSON to TOON converter to see token savings with your own data
Add the package for your language (npm or pip)
Convert your prompt data to TOON and compare results
Measure actual token savings and adjust your data structure for maximum efficiency
Can't find what you're looking for? Check out our GitHub discussions or open an issue.
Visit GitHub