Installation
Install the TOON SDK for TypeScript/JavaScript:Package:
Homepage: toonformat.dev
GitHub: github.com/toon-format/toon
@toon-format/toon v2.1.0 or laterHomepage: toonformat.dev
GitHub: github.com/toon-format/toon
Your First Encoding
Encode JavaScript objects to TOON format using theencode() function:
Notice how TOON declares the array length
[2] and field names {id,name,role} once, then streams row values. This is the key to TOON’s token efficiency.Your First Decoding
Decode TOON strings back to JavaScript objects using thedecode() function:
TOON provides 100% lossless, deterministic round-trips between JSON and TOON. No data is lost in conversion.
Working with Real Data
Let’s encode a more realistic dataset - employee records:- JSON (formatted): ~180 tokens
- TOON: ~95 tokens
- Savings: ~47%
Encoding Options
Customize encoding with options:See Encode Options for all available configuration options.
Streaming Large Datasets
For large datasets, useencodeLines() to stream output line by line without building the full string in memory:
- Datasets with thousands of records
- Writing to files or HTTP responses
- Memory-constrained environments
- Real-time data processing
For streaming decode, see
decodeFromLines(), decodeStreamSync(), and decodeStream().Using the CLI
For quick conversions without writing code, use the TOON CLI:See the CLI Guide for all options and examples.
Working with LLMs
TOON works best when you show the format instead of describing it. The structure is self-documenting:Pro tip: Wrap TOON in
```toon code blocks for input. For generation tasks, show the expected header template and use tab delimiters for better efficiency.Transforming Data with Replacer
Use thereplacer function to filter or transform values during encoding:
The
replacer function is similar to JSON.stringify’s replacer but includes path tracking. See the Replacer Function Guide for more examples.Next Steps
Now that you’ve learned the basics, explore these topics:Format Overview
Learn the complete TOON syntax and structure
Encoding Guide
Master all encoding options and patterns
Streaming
Handle large datasets efficiently
API Reference
Explore all functions and options
Interactive Playground
Experiment with TOON in your browser:- Official TOON Playground - Real-time conversion and token comparison
- Format Tokenization Explorer
- TOON Tools
Editor Support
Install syntax highlighting and validation for your editor:VS Code
Install the TOON Language Support extension:
Neovim
Install toon.nvim plugin
Tree-sitter
Use tree-sitter-toon for any editor with Tree-sitter support (Helix, Emacs, Zed)
Other Editors
Use YAML syntax highlighting as a close approximation
Need help? Check the GitHub repository or file an issue.
