Skip to main content

Installation

Install the TOON SDK for TypeScript/JavaScript:
Package: @toon-format/toon v2.1.0 or later
Homepage: toonformat.dev
GitHub: github.com/toon-format/toon

Your First Encoding

Encode JavaScript objects to TOON format using the encode() function:
Output:
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 the decode() function:
Output:
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:
Output:
Token Comparison:
  • 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, use encodeLines() to stream output line by line without building the full string in memory:
When to use streaming:
  • 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:
1

No installation needed

Use npx to run the CLI instantly:
2

Pipe from stdin

The CLI auto-detects format and supports pipes:
3

Analyze token savings

Use --stats to compare token counts:
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.
See the LLM Integration Guide for detailed strategies.

Transforming Data with Replacer

Use the replacer 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:

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.