Skip to main content

Token-Oriented Object Notation

TOON is a compact, human-readable encoding of JSON optimized for LLM prompts. Save up to 40% on tokens while maintaining 100% lossless conversion.

Why TOON?

LLM tokens cost money, and standard JSON is verbose. TOON combines YAML-like indentation with CSV-style tabular arrays to minimize token usage while remaining perfectly readable and maintaining full JSON compatibility.

Token Efficient

Save ~40% tokens compared to formatted JSON while achieving 76.4% accuracy vs JSON’s 75%

Lossless

100% bidirectional conversion between JSON and TOON with deterministic round-trips

LLM-Friendly

Explicit length declarations and field headers provide clear schema guardrails

Quick Example

Transform verbose JSON into compact TOON format:
{
  "users": [
    {
      "id": 1,
      "name": "Alice",
      "role": "admin"
    },
    {
      "id": 2,
      "name": "Bob",
      "role": "user"
    }
  ]
}

Key Features

TypeScript SDK

Full-featured encode/decode APIs with TypeScript types

Streaming Support

Memory-efficient processing for large datasets

CLI Tool

Quick conversions and token analysis from command line

Benchmarks

Proven 76.4% accuracy across 4 LLMs and 209 test questions

Get Started

1

Install the package

npm install @toon-format/toon
2

Encode your first data

import { encode } from '@toon-format/toon'

const data = {
  users: [
    { id: 1, name: 'Alice', role: 'admin' },
    { id: 2, name: 'Bob', role: 'user' }
  ]
}

console.log(encode(data))
// users[2]{id,name,role}:
//   1,Alice,admin
//   2,Bob,user
3

Decode back to JSON

import { decode } from '@toon-format/toon'

const toon = `users[2]{id,name,role}:
  1,Alice,admin
  2,Bob,user`

const result = decode(toon)
// { users: [{ id: 1, name: 'Alice', role: 'admin' }, ...] }

When to Use TOON

TOON excels with uniform arrays of objects, making it ideal for:
  • 📊 Tabular data with consistent structure (employee records, analytics, logs)
  • 🤖 LLM prompts where token efficiency matters
  • 📈 Time-series data with repeated field patterns
  • 🔄 Data pipelines requiring lossless JSON transformation
For deeply nested or non-uniform structures, compact JSON may be more efficient. See When to Use for detailed guidance.

Next Steps

Quickstart Guide

Get up and running in 5 minutes

Format Overview

Learn TOON syntax and structure

API Reference

Explore all encode/decode functions

LLM Integration

Use TOON with Claude, GPT, and other models

Build docs developers (and LLMs) love