Java Finally Gets TOON Support: json-io 4.85.0
I've seen the excellent TOON articles here on Dev.to lately (this one, this one), and noticed something: most implementations were for
TypeScript, Python, Go... but Java was underserved.
As the author of json-io, I decided to fix that.
What's TOON?
Quick refresher: TOON (Token-Oriented Object Notation) is designed for LLM efficiency. It looks like this:
name: John Smith
age: 30
skills[3]: Java,Spring,Kubernetes
address:
city: Austin
zip: 78701
vs JSON:
{
"name":"John Smith",
"age":30,"skills":["Java","Spring","Kubernetes"],
"address":{"city":"Austin","zip":"78701"}
}
Result: 40-50% fewer tokens, which directly translates to cost savings and larger context windows.
Java Usage
// Any Java object → TOON
String toon = JsonIo.toToon(employee, writeOptions);
// TOON → Java object
Employee emp = JsonIo.fromToon(toon, readOptions).asClass(Employee.class);
// Works with generics too
List<Employee> team = JsonIo.fromToon(toon, readOptions)
.asType(new TypeHolder<List<Employee>>(){});
Why This Matters for Java AI Development
If you're using:
- Spring AI - There's https://github.com/spring-projects/spring-ai/issues/4869 requesting TOON support
- LangChain4j - Token optimization is a hot topic in their discussions
- Any LLM API - You're paying per token
json-io gives you a drop-in solution today. Same library that handles your JSON can now handle TOON.
Full Feature Set
- Read AND write support (not just one direction)
- Complex object graphs with nested structures
- Collections, Maps, arrays, JDK object types (ZonedDateTime, etc.)
- Generic type support via TypeHolder
- String or Stream-based I/O
- All the robustness json-io is known for
Repo: https://github.com/jdereg/json-io
Happy to answer questions in the comments!
Top comments (0)