Token-Oriented Object Notation is a compact, human-readable format designed for passing structured data to Large Language Models with significantly reduced token usage.
Tip
Wrap your JSON in encode() before sending it to LLMs and save ~1/2 of the token cost for structured data!
AI is becoming cheaper and more accessible, but larger context windows allow for larger data inputs as well. LLM tokens still cost money – and standard JSON is verbose and token-expensive:
TOON conveys the same information with fewer tokens:
- 💸 Token-efficient: typically 30–60% fewer tokens than JSON
- 🤿 LLM-friendly guardrails: explicit lengths and field lists help models validate output
- 🍱 Minimal syntax: removes redundant punctuation (braces, brackets, most quotes)
- 📐 Indentation-based structure: replaces braces with whitespace for better readability
- 🧺 Tabular arrays: declare keys once, then stream rows without repetition
| 👤 Simple user object | 31 | 18 | 13 | 41.9% |
| 🏷️ User with tags | 48 | 28 | 20 | 41.7% |
| 📦 Small product catalog | 117 | 49 | 68 | 58.1% |
| 👥 API response with users | 123 | 53 | 70 | 56.9% |
| ⚙️ Nested configuration | 68 | 42 | 26 | 38.2% |
| 🛒 E-commerce order | 163 | 94 | 69 | 42.3% |
| 📊 Analytics data | 209 | 94 | 115 | 55.0% |
| 📈 Large dataset (50 records) | 2159 | 762 | 1397 | 64.7% |
| Total | 2918 | 1140 | 1778 | 60.9% |
Savings: 68 tokens (58.1% reduction)
JSON (117 tokens):
TOON (49 tokens):
Savings: 70 tokens (56.9% reduction)
JSON (123 tokens):
TOON (53 tokens):
Savings: 115 tokens (55.0% reduction)
JSON (209 tokens):
TOON (94 tokens):
Note
Measured with gpt-tokenizer using o200k_base encoding (used by GPT-5 and other modern models). Savings will vary across models and tokenizers.
Output:
TOON formatting is deterministic and minimal:
- Indentation: 2 spaces per nesting level.
- Lines:
- key: value for primitives (single space after colon).
- key: for nested/empty objects (no trailing space on that line).
- Arrays:
- Delimiter encoding: Comma delimiters are implicit in array headers (e.g., tags[3]:, items[2]{id,name}:). Tab and pipe delimiters are explicitly shown in array headers (e.g., tags[3|]:, items[2 ]{id name}:).
- Primitive arrays inline: key[N]: v1,v2 (comma) or key[N<delim>]: v1<delim>v2 (tab/pipe).
- Tabular arrays: key[N]{f1,f2}: … (comma) or key[N<delim>]{f1<delim>f2}: … (tab/pipe).
- List items: two spaces, hyphen, space (" - …").
- Whitespace invariants:
- No trailing spaces at end of any line.
- No trailing newline at end of output.
Simple objects with primitive values:
Nested objects:
Tip
TOON includes the array length in brackets (e.g., items[3]). When using comma delimiters (default), the delimiter is implicit. When using tab or pipe delimiters, the delimiter is explicitly shown in the header (e.g., tags[2|] or [2 ]). This encoding helps LLMs identify the delimiter and track the number of elements, reducing errors when generating or validating structured output.
When all objects share the same primitive fields, TOON uses an efficient tabular format:
Tabular formatting applies recursively: nested arrays of objects (whether as object properties or inside list items) also use tabular format if they meet the same requirements.
Arrays that don't meet the tabular requirements use list format:
When objects appear in list format, the first field is placed on the hyphen line:
Note
Nested array indentation: When the first field of a list item is an array (primitive, tabular, or nested), its contents are indented two spaces under the header line, and subsequent fields of the same object appear at that same indentation level. This remains unambiguous because list items begin with "- ", tabular arrays declare a fixed row count in their header, and object fields contain ":".
When you have arrays containing primitive inner arrays:
Empty containers have special representations:
TOON quotes strings only when necessary to maximize token efficiency. Inner spaces are allowed; leading or trailing spaces force quotes. Unicode and emoji are safe unquoted.
Note
When using alternative delimiters (tab or pipe), the quoting rules adapt automatically. Strings containing the active delimiter will be quoted, while other delimiters remain safe.
Keys are quoted when any of the following is true:
| Contains spaces, commas, colons, quotes, control chars | "full name", "a,b", "order:id", "tab\there" |
| Contains brackets or braces | "[index]", "{key}" |
| Leading hyphen | "-lead" |
| Numeric-only key | "123" |
| Empty key | "" |
Notes:
- Quotes and control characters in keys are escaped (e.g., "he said \"hi\"", "line\nbreak").
String values are quoted when any of the following is true:
| Empty string | "" |
| Contains active delimiter, colon, quote, backslash, or control chars | "a,b" (comma), "a\tb" (tab), "a|b" (pipe), "a:b", "say \"hi\"", "C:\\Users", "line1\\nline2" |
| Leading or trailing spaces | " padded ", " " |
| Looks like boolean/number/null | "true", "false", "null", "42", "-3.14", "1e-6", "05" |
| Starts with "- " (list-like) | "- item" |
| Looks like structural token | "[5]", "{key}", "[3]: x,y" |
Important
Delimiter-aware quoting: Unquoted strings never contain : or the active delimiter. This makes TOON reliably parseable with simple heuristics: split key/value on first : , and split array values on the delimiter declared in the array header. When using tab or pipe delimiters, commas don't need quoting – only the active delimiter triggers quoting for both array values and object values.
For arrays of objects to use the efficient tabular format, all of the following must be true:
| All elements are objects | No primitives in the array |
| Identical key sets | No missing or extra keys across rows |
| Primitive values only | No nested arrays or objects |
| Header delimiter | Comma is implicit in headers ([N]{f1,f2}); tab and pipe are explicit ([N ]{f1 f2}, `[N |
| Header key order | Taken from the first object |
| Header key quoting | Same rules as object keys; keys containing the active delimiter must be quoted |
| Row value quoting | Same rules as string values; values containing the active delimiter must be quoted |
If any condition fails, TOON falls back to list format.
Some non-JSON types are automatically normalized for LLM-safe output:
| Number (finite) | Decimal form, no scientific notation; -0 → 0 |
| Number (NaN, ±Infinity) | null |
| BigInt | Decimal digits (no quotes) |
| Date | ISO string in quotes (e.g., "2025-01-01T00:00:00.000Z") |
| undefined | null |
| function | null |
| symbol | null |
Number normalization examples:
Converts any JSON-serializable value to TOON format.
Parameters:
- value – Any JSON-serializable value (object, array, primitive, or nested structure). Non-JSON-serializable values (functions, symbols, undefined, non-finite numbers) are converted to null. Dates are converted to ISO strings, and BigInts are emitted as decimal integers (no quotes).
- options – Optional encoding options:
- indent?: number – Number of spaces per indentation level (default: 2)
- delimiter?: ',' | '\t' | '|' – Delimiter for array values and tabular rows (default: ',')
- lengthMarker?: '#' | false – Optional marker to prefix array lengths (default: false)
Returns:
A TOON-formatted string with no trailing newline or spaces.
Example:
Output:
The delimiter option allows you to choose between comma (default), tab, or pipe delimiters for array values and tabular rows. Alternative delimiters can provide additional token savings in specific contexts.
Using tab delimiters instead of commas can reduce token count further, especially for tabular data:
Output:
Benefits:
- Tabs are single characters and often tokenize more efficiently than commas.
- Tabs rarely appear in natural text, reducing the need for quote-escaping.
- The delimiter is explicitly encoded in the array header, making it self-descriptive.
Considerations:
- Some terminals and editors may collapse or expand tabs visually.
- String values containing tabs will still require quoting.
Pipe delimiters offer a middle ground between commas and tabs:
Output:
The lengthMarker option adds an optional hash (#) prefix to array lengths to emphasize that the bracketed value represents a count, not an index:
When incorporating TOON into your LLM workflows:
- Wrap TOON data in a fenced code block in your prompt.
- Tell the model: "Do not add extra punctuation or spaces; follow the exact TOON format."
- When asking the model to generate TOON, specify the same rules (2-space indentation, no trailing spaces, quoting rules).
- 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).
- TOON is designed for LLM contexts where human readability and token efficiency matter. It's not a drop-in replacement for JSON in APIs or storage.
- Tabular arrays require all objects to have exactly the same keys with primitive values only. Arrays with mixed types (primitives + objects/arrays), non-uniform objects, or nested structures will use a more verbose list format.
- Object key order is preserved from the input. In tabular arrays, header order follows the first object's keys.
- Arrays mixing primitives and objects/arrays always use list form:
items[2]: - a: 1 - [2]: 1,2
- Deterministic formatting: 2-space indentation, stable key order, no trailing spaces/newline.
MIT License © 2025-PRESENT Johann Schopplich
.png)



