Expand description
Minimal TOON encoder — Token-Oriented Object Notation.
TOON is a compact, human-readable encoding of JSON data for LLM prompts. It declares field names once in tabular headers and uses CSV-like rows, reducing token consumption by 30-50% for list-heavy responses.
§Examples
use serde::Serialize;
#[derive(Serialize)]
struct Item { name: String, value: i32 }
let items = vec![
Item { name: "alpha".into(), value: 1 },
Item { name: "beta".into(), value: 2 },
];
let toon = toon_encode::to_toon_string(&items).unwrap();
assert!(toon.contains("[2]{name,value}:"));Functions§
- encode_
toon - Encode a
serde_json::Valueas a TOON string at the given indentation depth. - to_
toon_ string - Encode any
Serializetype as a TOON string.