json2toon.co
Secure
7 min read

TOON Format Specification: Complete Guide to Grammar and Syntax

Discover the official TOON (Token-Oriented Object Notation) specification, ABNF grammar, data types, and key syntax rules of this modern serialization format.

By JSON to TOON Team

The TOON (Token-Oriented Object Notation) format is a groundbreaking data serialization specification designed specifically to optimize communication with Large Language Models (LLMs). Learn about the official specification, ABNF grammar, and key features of this format.

The Official TOON Specification

The official TOON format specification is hosted on GitHub in the toon-format/spec repository. It contains the complete format definition, including a formal ABNF (Augmented Backus-Naur Form) grammar, usage examples, and a set of validation tests. Learn more about what TOON is and how it compares to JSON or TONL.

The format defines a provisional media type of text/toon (pending IANA registration) and uses the .toon file extension. The character encoding is always UTF-8.

Core Syntax Rules

TOON combines the best features of several popular data formats, creating a unique syntax optimized for token efficiency:

1. Indentation-Based Structure

Like YAML, TOON uses whitespace (spaces) to define nesting. This eliminates the need for curly braces and significantly reduces token count:

user
  name John
  age 30
  email john@example.com

Instead of the JSON equivalent:

{
  "user": {
    "name": "John",
    "age": 30,
    "email": "john@example.com"
  }
}

2. Tabular Array Optimization

For uniform arrays of objects — where each object has the same fields — TOON offers a revolutionary approach. Field names are declared only once in the header, and data is streamed as rows, similar to CSV format:

| id | name    | role   | active
| 1  | Alice   | admin  | true
| 2  | Bob     | user   | true
| 3  | Charlie | user   | false

This eliminates the repetition of field names that multiply in each object within a JSON array. For large datasets, this optimization can yield 40-60% token savings.

3. Minimal Syntax

TOON eliminates redundant punctuation typical of JSON:

  • No quotes — strings don't require quotes unless they contain special characters
  • No curly braces — structure is defined by indentation
  • No commas — elements are separated by newlines
  • No colons — keys and values are separated by spaces

ABNF Grammar

The TOON specification includes a formal ABNF grammar that precisely defines the format's syntax. This grammar is available in the SPEC.md file within the specification repository. The formal grammar enables:

  • Creating validators compliant with the specification
  • Implementing parsers in any programming language
  • Automatic code generation from definitions
  • Verification of implementation correctness

Data Types in TOON

TOON supports all JSON data types, ensuring lossless conversion:

  • Objects — nested key-value structures
  • Arrays — sequences of values, including the optimized tabular format
  • Strings — text with optional quotes
  • Numbers — integers and floating-point numbers
  • Booleanstrue and false
  • Null — represented as null

When to Use TOON?

The TOON format is particularly effective in the following scenarios:

  • Structured data — API responses, configurations, business data
  • Uniform arrays — lists of users, products, database records
  • LLM communication — as an input format for language models
  • API cost optimization — fewer tokens = lower costs. See our cost optimization guide.

However, it's worth noting that for LLM outputs, JSON is still recommended due to broader tool and library support. For advanced features, consider TONL.

Reference Implementations

Official SDK implementations are available for the most popular languages:

  • TypeScript/JavaScript — full Node.js and browser support
  • Python — integration with popular AI frameworks

These libraries enable bidirectional JSON ↔ TOON conversion, allowing for easy integration with existing systems.

Conclusion

The TOON specification is a well-thought-out, thoroughly documented standard that solves a real problem — excessive token consumption when communicating with LLMs. Thanks to its formal ABNF grammar, official implementations, and active community, TOON is becoming an increasingly popular choice for developers building AI applications.

Ready to see the format in action? Try our JSON → TOON converter and discover how many tokens you can save on your own data. Learn more about what TOON is, how to optimize API costs, or compare TOON with TONL.

TOONSpecificationABNFSyntaxSerialization