Show HN: JSON-io – Java 库,支持 JSON、JSON5 和 TOON (LLM 令牌减少 40%)

1作者: jdereg5 个月前
我为 Java 序列化库 json-io 构建了 TOON 支持。TOON 是一种基于缩进的格式,专为 LLM(大型语言模型)应用设计,在这些应用中,每个 token 都会消耗费用并占用上下文窗口。 它与 JSON 存储相同的数据,但 token 数量减少了约 40-50%。没有大括号、方括号、逗号或不必要的引号。统一对象的数组会自动转换为类似 CSV 的表格。 JSON: ```json {"team":"Rockets","players":[{"name":"John","age":30},{"name":"Sue","age":27}]} ``` TOON: ``` team: Rockets players: name, age John, 30 Sue, 27 ``` json-io 可以读取/写入 JSON、JSON5 和 TOON 格式,支持 60 多种内置 Java 类型,循环引用,并且无需配置。它还有一个 Spring Boot Starter 和 Spring AI 模块。 GitHub: [https://github.com/jdereg/json-io](https://github.com/jdereg/json-io) TOON 规范: [https://toonformat.dev](https://toonformat.dev) Baeldung 文章: [https://www.baeldung.com/java-json-toon-format-libraries](https://www.baeldung.com/java-json-toon-format-libraries)
查看原文
I built TOON support into json-io, a Java serialization library. TOON is an indentation-based format designed for LLM applications where every token costs money and eats context window.<p>Same data as JSON, ~40-50% fewer tokens. No braces, brackets, commas, or unnecessary quoting. Arrays of uniform objects become CSV-like tables automatically.<p>JSON: {&quot;team&quot;:&quot;Rockets&quot;,&quot;players&quot;:[{&quot;name&quot;:&quot;John&quot;,&quot;age&quot;:30},{&quot;name&quot;:&quot;Sue&quot;,&quot;age&quot;:27}]}<p>TOON: team: Rockets players: name, age John, 30 Sue, 27<p>json-io reads&#x2F;writes JSON, JSON5, and TOON with 60+ built-in Java types, cycle support, and zero config. There&#x27;s also a Spring Boot starter and Spring AI module.<p>GitHub: <a href="https:&#x2F;&#x2F;github.com&#x2F;jdereg&#x2F;json-io" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;jdereg&#x2F;json-io</a> TOON spec: <a href="https:&#x2F;&#x2F;toonformat.dev" rel="nofollow">https:&#x2F;&#x2F;toonformat.dev</a> Baeldung article: <a href="https:&#x2F;&#x2F;www.baeldung.com&#x2F;java-json-toon-format-libraries" rel="nofollow">https:&#x2F;&#x2F;www.baeldung.com&#x2F;java-json-toon-format-libraries</a>