TOON (Token-Oriented Object Notation) is a compact alternative to JSON designed to reduce token consumption when sending structured data to LLMs. It uses indentation instead of braces, minimal quoting, and a tabular layout for uniform collections that states field names once rather than repeating them per object. Two Java libraries support TOON: JToon and json-io. Using json-io, you can serialize Java objects with JsonIo.toToon() and deserialize with JsonIo.fromToon(). Benchmarks using OpenAI's BPE tokenizer show 24-44% token savings for collections compared to JSON, with savings growing as collection size increases. For flat data, TOON is within 6% of CSV efficiency while also handling nested structures CSV cannot represent. A Spring AI starter (json-io-spring-ai-toon) enables automatic TOON conversion for tool call results via a ToonToolCallResultConverter annotation. TOON is best suited for LLM tool results, RAG payloads, and agentic workflows where token cost and context window size matter.
Table of contents
1. Overview2. What Is TOON?3. Java Libraries for TOON4. Writing Java Objects to TOON5. Reading TOON Back to Java6. Token Efficiency: Measuring the Difference7. Spring AI Integration8. When to Use TOON9. Conclusion1 Comment
Sort: