Can TOON Format Cut LLM Token Costs by Up to 60%?

This article explains how the TOON data‑serialization format reduces token usage and improves accuracy for large language model calls compared with traditional JSON, provides benchmark results, outlines scenarios where TOON is advantageous or unsuitable, and shows Java integration examples.

Programmer DD
Programmer DD
Programmer DD
Can TOON Format Cut LLM Token Costs by Up to 60%?

When large language models (LLMs) are used in business systems, structured data must be exchanged in a machine‑readable format. JSON is the de‑facto standard, but its punctuation (brackets, quotes, commas) adds a substantial token overhead, increasing API costs for high‑frequency calls.

Example JSON and token count

{
  "users": [
    {"id":1, "name":"Alice", "role":"admin"},
    {"id":2, "name":"Bob",   "role":"user"}
  ]
}

Token count: 47

TOON format

TOON replaces repeated punctuation with a one‑time field declaration and indentation. The same data can be expressed as:

users[2]{id,name,role}:
  1,Alice,admin
  2,Bob,user

Token count: 24 (≈40‑60 % fewer tokens than JSON).

Benchmark results

Across several serialization formats, TOON achieved the highest accuracy while using the fewest tokens.

TOON           ████████████████████   26.9 │ 73.9% acc │ 2,744 tokens
JSON compact   █████████████████░░░   22.9 │ 70.7% acc │ 3,081 tokens
YAML           ██████████████░░░░░░   18.6 │ 69.0% acc │ 3,719 tokens
JSON           ███████████░░░░░░░░░   15.3 │ 69.7% acc │ 4,545 tokens
XML            ████████░░░░░░░░░░   13.0 │ 67.1% acc │ 5,167 tokens

When TOON may be unsuitable

Deeply nested or irregular structures – compact JSON often uses fewer tokens.

Semi‑uniform arrays (≈40‑60 % fit a table format); if your pipeline already depends on JSON, staying with JSON may be simpler.

Pure tabular data – CSV is smaller than TOON for flat tables.

Latency‑critical applications – some deployments process compact JSON faster despite higher token counts; benchmark first‑token‑time (TTFT) and throughput.

Java integration

Add the TOON library to your Maven project. The required coordinates are:

groupId:    com.felipestanzani
artifactId: jtoon
version:    0.1.2

Core API methods:

// Java object → TOON string
String toon = JToon.encode(object);

// JSON string → TOON
String toon = JToon.encodeJson(jsonString);

// TOON → Java object
Object obj = JToon.decode(toonString);

// TOON → JSON string
String json = JToon.decodeToJson(toonString);

In scenarios with large volumes of uniform object arrays, TOON can markedly reduce token consumption and improve LLM retrieval accuracy, leading to lower API expenses.

JavaLLMData SerializationToken OptimizationTOON
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.