What is TOON format?

TOON (Token-Oriented Object Notation) is a compact, human-readable data serialization format designed specifically for Large Language Models (LLMs). Unlike JSON, which repeats field names for every object in an array, TOON declares field names once and then streams data in rows—similar to CSV but with explicit structure. This design typically reduces token usage by 30-60% compared to formatted JSON, especially for uniform arrays of objects. TOON combines YAML's indentation-based structure for nested objects with CSV's tabular efficiency, optimized for LLM contexts where token costs matter.

Tool Description

This converter transforms data between JSON and TOON formats bidirectionally. Simply paste your JSON data to generate compact TOON output, or convert TOON back to standard JSON. The tool uses the official @toon-format/toon library to ensure accurate conversion. TOON is particularly effective for datasets with repeated structures—such as user records, transaction logs, API responses, or any tabular data—where reducing token count improves efficiency when working with LLMs.

Examples

JSON Input:

{
  "users": [
    { "id": 1, "name": "Alice", "role": "admin" },
    { "id": 2, "name": "Bob", "role": "user" }
  ]
}

TOON Output:

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

Nested Structure Example:

JSON with nested objects converts to indented TOON format:

{
  "order": {
    "id": "ORD-456",
    "items": [
      { "sku": "A1", "qty": 2, "price": 19.99 },
      { "sku": "B2", "qty": 1, "price": 29.99 }
    ],
    "total": 69.97
  }
}

Becomes:

order:
  id: ORD-456
  items[2]{sku,qty,price}:
    A1,2,19.99
    B2,1,29.99
  total: 69.97

Features

  • Bidirectional conversion between JSON and TOON formats with full fidelity
  • Significant token reduction (30-60% fewer tokens vs JSON for uniform arrays)
  • Preserves data structure including nested objects, arrays, and primitive values
  • Automatic format detection and optimal encoding strategy
  • Human-readable output with clear tabular structure for uniform data
  • Type-safe conversion maintaining numbers, booleans, null, and strings correctly
  • Handles edge cases including empty arrays, nested structures, and mixed types
  • Real-time conversion with instant results as you type

Use Cases

  1. LLM API Optimization - Reduce token costs when sending structured data to GPT, Claude, or other LLMs by converting JSON payloads to TOON format before API calls
  2. Data Analysis Prompts - Prepare datasets for LLM analysis with more efficient encoding, allowing larger datasets within context limits
  3. Structured Data Generation - Use TOON in prompts to request LLMs generate tabular data more efficiently than JSON
  4. Log Processing - Convert application logs or analytics data to compact format for LLM-based analysis and summarization
  5. Configuration Management - Transform configuration files to token-efficient format when using LLMs for infrastructure management or DevOps tasks

Token Efficiency Details

TOON achieves significant token savings through several optimizations:

  • No repeated field names - Declares fields once in header instead of repeating for every object
  • Minimal punctuation - Removes redundant brackets, braces, and quotes where safe
  • Tabular format - Uses CSV-like rows for uniform arrays of objects
  • Delimiter flexibility - Supports comma (default), tab, or pipe delimiters for optimal tokenization

Token Comparison Example (using GPT-5 tokenizer):

  • JSON (formatted): 100 employee records ≈ 49,776 tokens
  • TOON: Same data ≈ 17,635 tokens (64.6% reduction)
  • CSV: ≈ 15,583 tokens (most compact, but lacks structure)

TOON provides the best balance between compactness and structural integrity for LLM applications.

Format Overview

Objects: Simple key-value pairs with indentation for nesting

id: 123
name: Ada
active: true

Arrays: Length declared in brackets, primitive arrays inline

tags[3]: reading,gaming,coding

Tabular Arrays: Uniform objects formatted as tables with field headers

items[2]{sku,qty,price}:
  A1,2,9.99
  B2,1,14.5

Quoting Rules: Strings are quoted only when necessary (containing delimiters, colons, or looking like other types)

Conversion Notes

When converting JSON to TOON:

  • Uniform arrays of objects automatically use tabular format
  • Nested structures maintain proper indentation
  • Non-JSON types (undefined, functions) convert to null
  • Dates convert to ISO strings
  • Numbers avoid scientific notation

When converting TOON to JSON:

  • Maintains standard JSON formatting with 2-space indentation
  • Validates array lengths and field consistency
  • Properly escapes special characters
  • Preserves type information (numbers, booleans, null)