Why a 10‑Year‑Old Java JSON Library Is Now Targeting LLMs with TOON
json-io, a decade‑old Java JSON library known for zero‑config, circular‑reference support, and lightweight size, has added full TOON (Token‑Oriented Object Notation) read/write capabilities, a token‑efficient format designed for LLMs that can cut serialization costs by 30‑60% and integrates seamlessly with Spring Boot and Spring AI.
Introduction
json-io is a Java JSON library created by John DeRegnaucourt in 2012. It became popular because it required zero configuration, supported circular references, and was lightweight (around 330 KB JAR).
After Jackson and Gson dominated the market, json-io faded from view, but the project has recently made a major move: version 4.85.0 adds full support for the TOON data format.
What is TOON?
TOON (Token‑Oriented Object Notation) is a serialization format designed specifically for large language model (LLM) interactions. By removing quotation marks, braces, commas, and using indentation for hierarchy, TOON reduces the token count of a payload by roughly 30‑60 % compared with JSON, directly lowering LLM API costs.
Although it resembles YAML, TOON retains type information and offers schema awareness, giving higher parsing accuracy for LLMs.
json‑io History and Core Features
Key reasons json‑io was once popular:
Zero configuration – objects can be serialized without annotations.
String json = JsonIo.toJson(myObject);
MyClass obj = JsonIo.toJava(json).asClass(MyClass.class);Circular‑reference support – uses @id and @ref to handle object graphs.
{
"@id": 1,
"name": "parent",
"child": {
"name": "child",
"parent": {"@ref": 1}
}
}Automatic polymorphic type handling – adds a @type field when needed.
Lightweight footprint – the JAR is about 330 KB, far smaller than the Jackson suite.
These traits earned json‑io a spot on json.org as a recommended Java library.
Why Add TOON Support?
With the explosion of LLM‑driven applications, Java developers need a format that minimizes token usage while preserving type fidelity. The author announced the addition on dev.to, noting the Java ecosystem lagged behind TypeScript, Python, and Go implementations of TOON.
Key advantages of json‑io’s TOON implementation:
Supports 60+ built‑in Java types (e.g., LocalDateTime, BigDecimal, UUID, Path) without custom converters.
Allows any serializable object as a map key, whereas the reference JToon library only permits strings.
Handles EnumSet, circular references, and retains full type information.
Stable release status versus the beta status of competing JToon.
Quick Start
Adding the Dependency
Maven :
<dependency>
<groupId>com.cedarsoftware</groupId>
<artifactId>json-io</artifactId>
<version>4.89.0</version>
</dependency>Gradle :
implementation 'com.cedarsoftware:json-io:4.89.0'Basic Usage
import com.cedarsoftware.io.JsonIo;
public class ToonDemo {
public static void main(String[] args) {
// Create an object
User user = new User("lengleng", 18, List.of("admin", "user"));
// Serialize to JSON
String json = JsonIo.toJson(user);
System.out.println("JSON:
" + json);
// Serialize to TOON (≈40 % token saving)
String toon = JsonIo.toToon(user, null);
System.out.println("TOON:
" + toon);
// Deserialize from TOON
User restored = JsonIo.fromToon(toon, null).asClass(User.class);
System.out.println("Restored: " + restored.getName());
}
}Sample output:
JSON:
{"name":"lengleng","age":18,"roles":["admin","user"]}
TOON:
name: lengleng
age: 18
roles:
- admin
- user
Restored: lenglengSpring Boot Integration
json‑io provides a Spring Boot starter that adds content‑negotiation support for TOON.
<dependency>
<groupId>com.cedarsoftware</groupId>
<artifactId>json-io-spring-boot-starter</artifactId>
<version>4.89.0</version>
</dependency>Controllers remain unchanged; the client selects the format 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 TOON with Spring AI
When building tools for Spring AI, you can register a TOON response‑format converter:
@Bean
public ToolResponseFormatConverter toonConverter() {
return new ToonToolResponseFormatConverter();
}Spring’s official blog (Nov 2025) documented this pattern, confirming TOON’s growing mainstream adoption.
Conclusion
By adding TOON support, json‑io bridges a gap for Java developers who need token‑efficient serialization for LLM‑driven services. The library retains its original strengths—zero configuration, circular‑reference handling, and a tiny footprint—while offering up to 60 % token savings, seamless Spring Boot integration, and compatibility with Spring AI tooling.
Java Architecture Diary
Committed to sharing original, high‑quality technical articles; no fluff or promotional content.
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.
