Why a Decade‑Old Java Library Is Jumping Into the AI Race with TOON

The article introduces TOON, a token‑oriented data format that cuts JSON token usage by 30‑60%, and explains how the veteran Java serialization library json‑io has added full TOON support, offering zero‑config, cyclic‑reference handling, and seamless Spring Boot integration for cost‑effective LLM applications.

Java Backend Technology
Java Backend Technology
Java Backend Technology
Why a Decade‑Old Java Library Is Jumping Into the AI Race with TOON

What Is TOON?

TOON (Token‑Oriented Object Notation) is a lightweight data format designed specifically for large language model (LLM) interactions. By removing quotes, braces, and commas, it reduces token count by 30‑60%, directly lowering the cost of token‑based LLM APIs.

json‑io’s History and New Direction

json‑io, created by John DeRegnaucourt in 2012, became popular for its zero‑configuration setup, built‑in support for cyclic references, and automatic polymorphic type handling. After years of being eclipsed by Jackson and Gson, version 4.85.0 (released January 2026) adds comprehensive TOON read/write capabilities.

I saw many TOON articles for TypeScript, Python, and Go, but Java lagged behind. As the author of json‑io, I decided to fill that gap.

Key Features of json‑io’s TOON Support

Built‑in Types: Over 60 Java types (e.g., LocalDateTime, BigDecimal, UUID, Path) are serializable out of the box.

Map Key Types: Any serializable type, whereas the JToon reference implementation only supports strings.

EnumSet: Supported in json‑io, not in JToon.

Cyclic References: Fully supported, unlike JToon.

Dependencies: Relies only on java‑util, keeping the library lightweight (≈330 KB JAR).

Stability: Marked stable, while the JToon counterpart is still in beta.

Quick Start

Add 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) {
        User user = new User("lengleng", 18, List.of("admin", "user"));
        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());
    }
}

Output comparison shows the compact TOON representation without quotes or commas.

Spring Boot Integration

Add the starter:

<dependency>
  <groupId>com.cedarsoftware</groupId>
  <artifactId>json-io-spring-boot-starter</artifactId>
  <version>4.89.0</version>
</dependency>

Controllers remain unchanged; the response format is negotiated 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/1

Using with Spring AI

When working with Spring AI, register a TOON response‑format converter:

@Bean
public ToolResponseFormatConverter toonConverter() {
    return new ToonToolResponseFormatConverter();
}

This enables LLM tools to receive compact TOON payloads, reducing token consumption while keeping the public JSON API compatible.

LLMSpring BootTOONjson-io
Java Backend Technology
Written by

Java Backend Technology

Focus on Java-related technologies: SSM, Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading. Occasionally cover DevOps tools like Jenkins, Nexus, Docker, and ELK. Also share technical insights from time to time, committed to Java full-stack development!

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.