Overview
Introduction
When structured data is headed into a language model's context window, every repeated key name and punctuation character is tokens spent on formatting rather than content. TOON trades some of JSON and YAML's generality for a format that says a field's name once per array instead of once per row.
This tool parses YAML (already this site's most flexible structured-data input format) and re-encodes the resulting value as TOON, so you can paste YAML config or data and get a more token-efficient representation of the same structure back out.
What Is YAML to TOON?
A YAML-to-TOON converter parses YAML into a plain JavaScript value, then walks that value recursively, choosing one of four encodings at each level: key: value lines for a mapping, a nested key: line followed by deeper-indented lines for a nested mapping, one inline key[N]: v1,v2,v3 line for an array of primitives, or a key[N]{field1,field2}: tabular block for an array of objects that all share the exact same fields.
Anything that doesn't fit those tabular shapes (a mixed-type array, or objects with differing field sets) falls back to an indented list of - -prefixed entries, so every possible YAML value still has a defined TOON encoding, just not always the most compact one.
How YAML to TOON Works
The encoder recurses depth-first: object values are inspected key by key, with arrays and nested objects routed to their own specialized encoders, and scalars written directly as key: value. Every nesting level adds two spaces of indentation, matching YAML's own convention.
For an array, every item is checked: all-scalar arrays become one inline comma-separated line; all-object arrays with an identical key set become a tabular block (field order taken from the first object); anything else becomes an indented - -prefixed fallback list, recursing into each item the same way. Scalars are quoted only when necessary, comma, colon, brackets, braces, #, a literal newline, surrounding whitespace, or ambiguity with true/false/null/a number, to keep the common case unquoted and compact.
When To Use YAML to TOON
Use it before pasting structured data (API responses, config, tabular records) into an LLM prompt where every token counts toward a context budget.
It's also a quick way to see how much more compact a given YAML document could be once its repeated key names are factored out into a tabular header.
Often used alongside YAML to Canonical Normalizer, YAML Formatter & Prettifier and YAML Sorter.
Features
Advantages
- Encodes arrays of uniform objects as a compact tabular block, eliminating repeated field names that JSON or block-style YAML would otherwise repeat per item.
- Falls back gracefully to a readable list format for non-uniform arrays instead of failing or losing data.
- Quotes only the scalars that actually need it, keeping the common case as compact, unquoted text.
- Runs entirely client-side, so data being prepared for a prompt never leaves your browser.
Limitations
- TOON is a much newer, less standardized format than YAML or JSON; there's no single canonical parser to validate round-trips against, so this encoder follows the community specification as documented rather than a formally ratified spec.
- The tabular array encoding only triggers when every object in the array has the exact same set of keys; a single differing or missing field falls the whole array back to the less compact list form.
- Deeply nested, non-uniform arrays-of-arrays fall back to a nested - -prefixed representation whose exact layout is this tool's own reasonable interpretation, since the TOON specification doesn't exhaustively define every nesting combination.
Examples
Best Practices & Notes
Best Practices
- Reach for TOON specifically when the data is headed into an LLM's context window; for everyday config editing, YAML's comments and familiarity usually still win.
- Keep arrays of records uniform (same fields on every item) if you want the compact tabular encoding rather than the list fallback.
- Double-check a few converted values by eye when your data has fields that look like true, false, null, or numbers as strings, they'll be quoted in the output specifically to preserve their string type.
Developer Notes
The encoder is intentionally self-contained (no TOON parsing library, since this is a one-directional encode-only tool): needsQuoting mirrors TOON's documented ambiguity rules, uniformFields does a simple key-set-equality check across every item before committing to the tabular header, and the non-uniform array fallback reuses the same object-line encoder internally, just re-indented and given a - prefix for its first line, so nested structures inside a fallback list still render consistently with the rest of the document.
YAML to TOON Use Cases
- Compacting a YAML data payload before including it in an LLM prompt to reduce token usage
- Converting a list of uniform records (users, log entries, config rows) into TOON's compact tabular form
- Comparing YAML and TOON side by side to estimate potential token savings for a given dataset
- Producing a terse, structured representation of config data for inclusion in documentation
Common Mistakes
- Expecting an array with even one object missing or adding a field to still use the compact tabular form, any field mismatch falls the whole array back to the - -prefixed list encoding.
- Assuming TOON output can be parsed back into YAML or JSON by this site's other tools, this converter is one-directional (YAML in, TOON out); there's no TOON parser elsewhere in this category.
- Forgetting that values like "true" or "123" (strings that merely look like other types) come back double-quoted, that's intentional, to keep them from being misread as a boolean or number.
Tips
- If your data is naturally tabular (a list of similarly-shaped records), restructure it as an array of objects with identical keys before converting, to get TOON's most compact encoding.
- Use YAML to Canonical Normalizer first if you want a consistent key order feeding into the TOON conversion.
- For quick token-savings comparisons, convert the same document with YAML Minifier and this tool side by side.