Why json-io’s New TOON Support Could Cut LLM Token Costs by Up to 60%
The article introduces json-io’s recent addition of full TOON format support—a token‑oriented data notation that removes JSON’s syntactic noise, saving 30‑60% of tokens for LLM APIs, and shows how to integrate it with Java, Maven, and Spring Boot.
json-io is a decade‑old Java JSON library that originally attracted users with zero‑configuration, circular‑reference handling, automatic polymorphic type support, and a tiny footprint (≈330 KB). After years of being eclipsed by Jackson and Gson, the library now adds full support for TOON (Token‑Oriented Object Notation).
What is TOON?
TOON is a data format designed specifically for large language model (LLM) interactions. Compared with JSON, it removes quotes, braces, commas and uses indentation to express hierarchy, which reduces the token count by roughly 30‑60 %—a significant cost saving when LLM APIs charge per token.
{
"name": "John Smith",
"age": 30,
"email": "[email protected]",
"active": true,
"roles": ["admin", "user"]
}becomes
name: John Smith
age: 30
email: [email protected]
active: true
roles:
- admin
- userAlthough it looks similar to YAML, TOON retains type information and is schema‑aware, giving LLMs higher parsing accuracy.
Why Add TOON Support?
With LLM applications proliferating, Java developers need a compact, LLM‑friendly serialization format. The author, John DeRegnaucourt, noted the Java ecosystem lagged behind TypeScript, Python, and Go implementations and decided to fill the gap.
Feature Comparison (json‑io vs JToon)
Built‑in types : json‑io supports 60+ (e.g., LocalDateTime, BigDecimal, UUID, Path); JToon supports ~15.
Map key types : json‑io accepts any serializable key; JToon only strings.
EnumSet : supported by json‑io, not by JToon.
Circular references : supported by json‑io, not by JToon.
Dependencies : json‑io relies on java‑util; JToon depends on Jackson.
Status : json‑io is stable; JToon is in beta.
Quick Start
Add the library via Maven or Gradle:
<dependency>
<groupId>com.cedarsoftware</groupId>
<artifactId>json-io</artifactId>
<version>4.89.0</version>
</dependency> implementation 'com.cedarsoftware:json-io:4.89.0'Basic usage:
import com.cedarsoftware.io.JsonIo;
public class ToonDemo {
public static void main(String[] args) {
User user = new User("lengleng", 18, List.of("admin", "user"));
String json = JsonIo.toJson(user);
System.out.println("JSON:
" + json);
String toon = JsonIo.toToon(user, null);
System.out.println("TOON:
" + toon);
User restored = JsonIo.fromToon(toon, null).asClass(User.class);
System.out.println("Restored: " + restored.getName());
}
}Output shows the token‑saving difference between JSON and TOON.
Spring Boot Integration
Include the starter dependency:
<dependency>
<groupId>com.cedarsoftware</groupId>
<artifactId>json-io-spring-boot-starter</artifactId>
<version>4.89.0</version>
</dependency>No changes are required in existing controllers; content negotiation is handled via the Accept header:
# Request JSON
curl -H "Accept: application/json" http://localhost:8080/user/1
# Request TOON
curl -H "Accept: application/vnd.toon" http://localhost:8080/user/1Using with Spring AI
When working with Spring AI, define a bean to convert tool responses to TOON:
@Bean
public ToolResponseFormatConverter toonConverter() {
return new ToonToolResponseFormatConverter();
}Spring’s official blog (Nov 2025) documents this usage, indicating that TOON is gaining mainstream attention.
Overall, json‑io’s TOON support lets Java developers keep their existing JSON APIs while offering a compact, LLM‑optimized format that can reduce token consumption and cost.
macrozheng
Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
