|
8 | 8 | [](https://www.npmjs.com/package/@toon-format/toon) |
9 | 9 | [](./LICENSE) |
10 | 10 |
|
11 | | -**Token-Oriented Object Notation** is a compact, human-readable serialization format designed for passing structured data to Large Language Models with significantly reduced token usage. It's intended for LLM input, not output. |
| 11 | +**Token-Oriented Object Notation** is a compact, human-readable serialization format designed for passing structured data to Large Language Models with significantly reduced token usage. It's intended for *LLM input* as a lossless, drop-in representation of JSON data. |
12 | 12 |
|
13 | 13 | TOON's sweet spot is **uniform arrays of objects** – multiple fields per row, same structure across items. It borrows YAML's indentation-based structure for nested objects and CSV's tabular format for uniform data rows, then optimizes both for token efficiency in LLM contexts. For deeply nested or non-uniform data, JSON may be more efficient. |
14 | 14 |
|
| 15 | +TOON achieves CSV-like compactness while adding explicit structure that helps LLMs parse and validate data reliably. |
| 16 | + |
15 | 17 | > [!TIP] |
16 | 18 | > Think of TOON as a translation layer: use JSON programmatically, convert to TOON for LLM input. |
17 | 19 |
|
@@ -71,41 +73,48 @@ For small payloads, JSON/CSV/YAML work fine. TOON's value emerges at scale: when |
71 | 73 | > [!TIP] |
72 | 74 | > Try the interactive [Format Tokenization Playground](https://www.curiouslychase.com/playground/format-tokenization-exploration) to compare token usage across CSV, JSON, YAML, and TOON with your own data. |
73 | 75 |
|
74 | | -The benchmarks test datasets that favor TOON's strengths (uniform tabular data). Real-world performance depends heavily on your data structure. |
| 76 | +### Token Efficiency |
| 77 | + |
| 78 | +Token counts are measured using the GPT-5 `o200k_base` tokenizer via [`gpt-tokenizer`](https://github.com/niieani/gpt-tokenizer). Savings are calculated against formatted JSON (2-space indentation) as the primary baseline, with additional comparisons to compact JSON (minified), YAML, and XML. Actual savings vary by model and tokenizer. |
| 79 | + |
| 80 | +The benchmarks use datasets optimized for TOON's strengths (uniform tabular data). Real-world performance depends on your data structure. |
| 81 | + |
| 82 | +> [!NOTE] |
| 83 | +> CSV/TSV isn't shown in the token-efficiency chart because it doesn't encode nesting without flattening. For flat datasets, see CSV token counts in the [Retrieval Accuracy](#retrieval-accuracy) tables. |
75 | 84 |
|
76 | 85 | <!-- automd:file src="./benchmarks/results/token-efficiency.md" --> |
77 | 86 |
|
78 | 87 | ### Token Efficiency |
79 | 88 |
|
80 | 89 | ``` |
81 | 90 | ⭐ GitHub Repositories ██████████████░░░░░░░░░░░ 8,745 tokens |
82 | | - vs JSON (-42.3%) 15,145 |
83 | | - vs JSON compact (-23.7%) 11,455 |
84 | | - vs YAML (-33.4%) 13,129 |
85 | | - vs XML (-48.8%) 17,095 |
| 91 | + vs JSON (−42.3%) 15,145 |
| 92 | + vs JSON compact (−23.7%) 11,455 |
| 93 | + vs YAML (−33.4%) 13,129 |
| 94 | + vs XML (−48.8%) 17,095 |
86 | 95 |
|
87 | 96 | 📈 Daily Analytics ██████████░░░░░░░░░░░░░░░ 4,507 tokens |
88 | | - vs JSON (-58.9%) 10,977 |
89 | | - vs JSON compact (-35.7%) 7,013 |
90 | | - vs YAML (-48.8%) 8,810 |
91 | | - vs XML (-65.7%) 13,128 |
| 97 | + vs JSON (−58.9%) 10,977 |
| 98 | + vs JSON compact (−35.7%) 7,013 |
| 99 | + vs YAML (−48.8%) 8,810 |
| 100 | + vs XML (−65.7%) 13,128 |
92 | 101 |
|
93 | 102 | 🛒 E-Commerce Order ████████████████░░░░░░░░░ 166 tokens |
94 | | - vs JSON (-35.4%) 257 |
95 | | - vs JSON compact (-2.9%) 171 |
96 | | - vs YAML (-15.7%) 197 |
97 | | - vs XML (-38.7%) 271 |
| 103 | + vs JSON (−35.4%) 257 |
| 104 | + vs JSON compact (−2.9%) 171 |
| 105 | + vs YAML (−15.7%) 197 |
| 106 | + vs XML (−38.7%) 271 |
98 | 107 |
|
99 | 108 | ───────────────────────────────────────────────────────────────────── |
100 | 109 | Total ██████████████░░░░░░░░░░░ 13,418 tokens |
101 | | - vs JSON (-49.1%) 26,379 |
102 | | - vs JSON compact (-28.0%) 18,639 |
103 | | - vs YAML (-39.4%) 22,136 |
104 | | - vs XML (-56.0%) 30,494 |
| 110 | + vs JSON (−49.1%) 26,379 |
| 111 | + vs JSON compact (−28.0%) 18,639 |
| 112 | + vs YAML (−39.4%) 22,136 |
| 113 | + vs XML (−56.0%) 30,494 |
105 | 114 | ``` |
106 | 115 |
|
107 | 116 | <details> |
108 | | -<summary><strong>Show detailed examples</strong></summary> |
| 117 | +<summary><strong>View detailed examples</strong></summary> |
109 | 118 |
|
110 | 119 | #### ⭐ GitHub Repositories |
111 | 120 |
|
@@ -242,9 +251,6 @@ metrics[5]{date,views,clicks,conversions,revenue,bounceRate}: |
242 | 251 |
|
243 | 252 | <!-- /automd --> |
244 | 253 |
|
245 | | -> [!NOTE] |
246 | | -> Token savings are measured against formatted JSON (2-space indentation) as the primary baseline. Additional comparisons include compact JSON (minified), YAML, and XML to provide a comprehensive view across common data formats. Measured with [`gpt-tokenizer`](https://github.com/niieani/gpt-tokenizer) using `o200k_base` encoding (GPT-5 tokenizer). Actual savings vary by model and tokenizer. |
247 | | -
|
248 | 254 | <!-- automd:file src="./benchmarks/results/retrieval-accuracy.md" --> |
249 | 255 |
|
250 | 256 | ### Retrieval Accuracy |
@@ -909,6 +915,7 @@ By default, the decoder validates input strictly: |
909 | 915 | - Format familiarity and structure matter as much as token count. TOON's tabular format requires arrays of objects with identical keys and primitive values only. When this doesn't hold (due to mixed types, non-uniform objects, or nested structures), TOON switches to list format where JSON can be more efficient at scale. |
910 | 916 | - **TOON excels at:** Uniform arrays of objects (same fields, primitive values), especially large datasets with consistent structure. |
911 | 917 | - **JSON is better for:** Non-uniform data, deeply nested structures, and objects with varying field sets. |
| 918 | + - **CSV is more compact for:** Flat, uniform tables without nesting. TOON adds minimal overhead (`[N]` length markers, delimiter scoping, deterministic quoting) to improve LLM reliability while staying close to CSV's token efficiency. |
912 | 919 | - **Token counts vary by tokenizer and model.** Benchmarks use a GPT-style tokenizer (cl100k/o200k); actual savings will differ with other models (e.g., [SentencePiece](https://github.com/google/sentencepiece)). |
913 | 920 | - **TOON is designed for LLM input** where human readability and token efficiency matter. It's **not** a drop-in replacement for JSON in APIs or storage. |
914 | 921 |
|
|
0 commit comments