Building an AI startup?
You might be eligible for our Startup Program. Get fully funded access to the infrastructure you’re reading about right now (up to $20K value).
What is TOON?
Token-Oriented Object Notation (TOON) is a compact, human-readable encoding of the JSON data model designed specifically for LLM input. It minimizes token usage while maintaining full data fidelity, making it an excellent choice for reducing costs when processing large amounts of structured data. TOON combines YAML’s indentation-based structure with a CSV-style tabular layout for uniform arrays, achieving 30-60% token reduction compared to standard JSON.TOON is a translation layer - use JSON programmatically in your code, and encode it as TOON when passing data to LLMs.
How TOON Works
The Problem with JSON
Standard JSON repeats field names for every record, which is token-expensive:The TOON Solution
TOON declares fields once and streams data as compact rows:[3]declares the array length (helps detect truncation){id,name,price}declares field names once- Each row contains comma-separated values
Token Savings Example
JSON
235 tokensVerbose with repeated keys
TOON
106 tokens~55% reduction
JSON (235 tokens)
TOON (106 tokens)
When to Use TOON
TOON excels with flat, uniform arrays of objects - data where items share the same structure across all records.
Ideal Use Cases
When NOT to Use TOON
Avoid TOON When:
Data is deeply nested
Data is deeply nested
Complex objects with multiple nesting levels don’t benefit from TOON’s tabular format. JSON-compact often uses fewer tokens for such structures.Example: LinkedIn profiles with nested experience, education, and skills objects.
Data is non-uniform
Data is non-uniform
When array items have different fields or optional properties, TOON’s header-based approach breaks down.Example: Mixed product types with varying attributes.
Using Bright Data MCP structured endpoints
Using Bright Data MCP structured endpoints
Most Bright Data web data endpoints return richly nested JSON with hierarchical relationships. TOON won’t provide meaningful savings here.Example:
web_data_amazon_product, web_data_linkedin_person_profile, etc.TOON with Bright Data MCP
Understanding the Limitation
Bright Data’s MCP server returns structured data from platforms like Amazon, LinkedIn, Instagram, and more. This data is typically nested and hierarchical, making it unsuitable for TOON optimization.- Remote MCP (SSE)
- Local MCP (STDIO)
Connect via Server-Sent Events:
When TOON Can Help
While most Bright Data endpoints return nested data, there are scenarios where TOON can be beneficial:1
Flatten the data first
Post-process MCP responses to extract flat arrays before encoding to TOON.
2
Use for batch results
When using
scrape_batch or search_engine_batch, the URL/content pairs can be flattened.3
Custom extraction
Use the
extract tool with a prompt that requests flat, tabular data.Quick Start with TOON
How to install TOON
How to encode and decode data
How to use the CLI
Practical Example: Using TOON with MCP Client
This example demonstrates a complete workflow: connecting to Bright Data’s MCP server, fetching data, flattening the nested response, and converting it to TOON format for token-efficient LLM processing.Full MCP Client Example
Batch Processing Multiple Products
For larger datasets, the token savings become even more significant:Creating a Reusable Flattener
For production use, create a reusable utility with the correct MCP field mappings:Summary
Use TOON For
- Flat, uniform arrays
- Tabular data structures
- Large datasets with repeated schemas
- Post-processed, flattened MCP data
Avoid TOON For
- Deeply nested objects
- Non-uniform data structures
- Direct MCP endpoint responses
- Complex hierarchical data
Bottom Line: TOON is a powerful tool for token optimization, but it’s designed for flat, uniform data. Bright Data MCP responses are typically nested, so apply TOON only after flattening the data to a tabular structure.
Where to learn more
TOON Specification
Official format specification
TypeScript SDK
NPM package documentation
TOON Website
Interactive playground and docs