A Serde-compatible TOON serialization library for Rust.
TOON (Token-Oriented Object Notation) is a compact serialization format optimized for LLMs, using 30-60% fewer tokens than JSON.
Example - Same data, different sizes:
// JSON: 171 characters
[
{
"id": 1,
"name": "Alice",
"email": "[email protected]",
"active": true
},
{
"id": 2,
"name": "Bob",
"email": "[email protected]",
"active": true
}
]
// TOON: 86 characters (50% reduction)
[2]{active,email,id,name}:
true,alice@example.com,1,Alice
true,bob@example.com,2,BobSee examples/token_efficiency.rs.
[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_toon = "0.2"use serde::{Deserialize, Serialize};
use serde_toon::{to_string, from_str};
#[derive(Serialize, Deserialize)]
struct User {
id: u32,
name: String,
}
let user = User { id: 123, name: "Alice".into() };
let toon = to_string(&user)?; // Serialize to TOON
let back: User = from_str(&toon)?; // Deserialize from TOONuse serde_toon::{toon, to_string};
let data = toon!({
"users": [
{"id": 1, "name": "Alice"},
{"id": 2, "name": "Bob"}
],
"active": true
}); // toon! macro -> serde_toon::Value
let serialized = to_string(&data)?;See examples/dynamic_values.rs, examples/macro.rs.
- Full Serde integration
- Zero-copy deserialization
- Configurable output
- Rich error messages
- No unsafe code
See https://docs.rs/serde_toon
MIT OR Apache-2.0