Skip to main content

Crate toon_encode

Crate toon_encode 

Source
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::Value as a TOON string at the given indentation depth.
to_toon_string
Encode any Serialize type as a TOON string.