Convert JSON to TOON format. Reduce LLM token usage by 30-60% with intelligent data optimization.
Want a ready-made starting point for your next piece of writing?
Browse the Prompt LibraryTOON (Token-Oriented Object Notation) is a modern data format optimized for LLM consumption, reducing token usage by 30-60% compared to JSON while maintaining human readability.
TOON combines YAML's indentation-based structure with CSV's tabular layout for uniform arrays. It eliminates redundant JSON punctuation (braces, brackets, repeated keys) while maintaining clarity. Perfect for RAG pipelines, LLM agents, and AI workflows with structured data.
TOON reduces API costs and increases effective context windows by declaring array structure once in headers, then streaming values in tabular rows. A typical JSON payload using 89 tokens becomes just 45 tokens in TOON, a 50% reduction. Studies show 30-60% token savings on large uniform arrays.
Use TOON for LLM prompts with uniform data arrays (user records, inventory, logs), RAG document storage, and structured AI outputs. Use JSON for API definitions, deeply nested structures, non-uniform data, and when universal compatibility is required across all systems.
The key TOON optimization: uniform object arrays become CSV-like tables. Format: arrayName[length]{field1,field2}: followed by indented rows of comma-separated values. Each row becomes an object with the declared fields. All values must be primitives (no nested objects).
Strings are unquoted by default in TOON. Use quotes only for: leading/trailing spaces, strings containing delimiters (comma, colon), reserved keywords (true, false, null), or values that look like numbers. This reduces token count while preventing ambiguity.
Keep JSON for application APIs and data exchange for universal compatibility. Convert to TOON only when sending data to LLMs for prompts, RAG retrieval, or structured outputs. This maximizes both interoperability and token efficiency where it matters most.
Get answers to common questions about our platform and how it can help your business.
TOON (Token-Oriented Object Notation) is a data serialization format specifically optimized for LLM consumption. Unlike JSON's verbose braces and repeated keys, TOON uses indentation for objects (like YAML) and tabular format for uniform arrays (like CSV). For example, a JSON array of user objects with repeated "id", "name", "role" keys becomes a single header row followed by data rows, reducing token usage by 30-60% while remaining human-readable.
Token reduction directly impacts three critical factors. First, API costs: LLM pricing is per-token, so 50% fewer tokens means 50% lower costs. Second, context windows: more efficient formats let you fit more data in limited context. Third, processing speed: fewer tokens means faster generation. A prompt that costs $0.10 in JSON might cost $0.04 in TOON. For high-volume AI applications processing millions of requests, this saves thousands of dollars monthly.
TOON excels with uniform arrays of objects where all items share identical field sets with primitive values. Perfect use cases: database query results (user lists, product catalogs, log entries), API responses with repeated structures, RAG document collections, and structured LLM outputs. It underperforms with deeply nested objects, mixed-type arrays, or pure hierarchical data where JSON's explicit structure is clearer.
TOON automatically falls back to list notation using hyphen prefixes (- item) for non-uniform arrays, similar to YAML. Each element is parsed independently and can be any type: primitives, objects, or nested arrays. While this doesn't provide the token savings of tabular format, it maintains compatibility with all JSON structures. The converter detects uniformity automatically and chooses the optimal representation.
Yes, TOON is a lossless format for all standard JSON data types (objects, arrays, strings, numbers, booleans, null). The conversion preserves structure and values with proper escape sequence handling. However, edge cases like NaN, Infinity, and undefined convert to null (same as JSON.stringify behavior). Special number formats, BigInt values, and Date objects follow standard JSON serialization rules.
TOON supports three delimiters for tabular arrays: comma (default, most compact), tab (better for copy-paste to Excel/spreadsheets), and pipe (clearer visual separation for strings containing commas). Choose comma for maximum token efficiency in LLM prompts, tab when you need to view/edit data in spreadsheet tools, and pipe when your data frequently contains comma-separated text that would require excessive quoting.
TOON uses 2-space indentation (configurable) to denote nesting depth, similar to YAML or Python. Each indentation level represents one level of object nesting. Unlike JSON's explicit braces, TOON infers structure from indentation alignment. Key-value pairs at the same indentation level belong to the same object. This eliminates brace tokens while maintaining clear visual hierarchy. Always use consistent spacing - mixing tabs and spaces causes parsing errors.
Key folding collapses single-key wrapper chains into dotted paths (e.g., data.metadata.items instead of nested objects). Enable it for deeply nested JSON with sequential single-key wrappers to save tokens and improve readability. Disable it if you need to preserve exact object hierarchy or if your application expects specific nested structure. It's particularly useful for configuration files and API responses with verbose nesting patterns.
The converter uses word-based approximation (~1.3 tokens per word plus punctuation counting) which provides ballpark estimates accurate to ±10-15%. Actual tokenization varies by model (GPT uses byte-pair encoding, Claude uses different tokenizers). For precise counts, use model-specific tokenizers like tiktoken (OpenAI) or claude-tokenizer (Anthropic). The estimates are sufficient for comparing formats and understanding relative savings.
The converter implements 1MB input size limits to prevent DoS attacks through memory exhaustion. All processing is client-side - your data never leaves your browser. When implementing TOON in production: validate all parsed data against schemas, sanitize string values to prevent injection attacks, never trust user-provided TOON without validation, implement rate limiting for conversion endpoints, and be cautious with sensitive data in logs or error messages.
Yes, TOON supports full Unicode characters in strings. Special characters are handled through quoting: strings containing delimiters, colons, or looking like reserved keywords get automatically quoted. Unicode characters (emoji, international text, symbols) remain unquoted unless they conflict with TOON syntax. Escape sequences (\n, \t, \) work like JSON. The converter handles encoding/decoding transparently.
Parse the TOON string and catch exceptions, since valid TOON parses without errors. Check for consistent indentation (no mixing tabs/spaces), array length declarations that match actual rows, tabular array field counts that match values per row, proper delimiter separation, and balanced quotes in strings. For strict validation, parse to JSON then back to TOON and verify round-trip consistency. Consider JSON Schema validation on the parsed output for structure validation.
JSON parsing is generally faster due to decades of optimization in browser engines and language runtimes. TOON parsing requires indentation tracking and tabular array expansion, adding computational overhead. However, for LLM applications, the token reduction benefits far outweigh parsing time differences. Use JSON for real-time APIs and client-server communication. Use TOON for LLM prompts where token efficiency matters more than parsing speed.
Studies show TOON improves LLM data retrieval accuracy by several percentage points due to explicit structure serving as "guardrails." Tabular format makes patterns more obvious to models - field headers declare expected structure, aligned rows highlight relationships, reduced punctuation noise improves focus on actual data. For tasks like data extraction, entity recognition, and structured output generation, TOON's clarity helps models produce more accurate results.
Absolutely - TOON is ideal for RAG! Store documents in TOON format to reduce embedding vector count (each chunk has fewer tokens), fit more context in retrieval results (30-60% more data per context window), and improve parsing accuracy when LLMs process retrieved chunks. Convert structured data (database results, API responses) to TOON before embedding. The token savings compound: reduced storage, faster retrieval, lower LLM costs, and better accuracy.
Deeply nested JSON converts to indented TOON structure, preserving all nesting levels through 2-space indentation. Each level adds indentation. However, TOON doesn't provide significant token savings for deep hierarchies - the benefit comes from uniform arrays, not nesting. For very deep structures (8+ levels), JSON's explicit braces may actually be clearer. TOON works best with moderate nesting (2-4 levels) containing uniform arrays.
The converter provides detailed error messages with line/column information for JSON parsing. Common JSON errors: unclosed brackets, trailing commas, unquoted keys. The converter validates input before conversion and displays specific error locations. Always validate JSON before conversion, wrap parsing in try-catch blocks, log parsing errors for debugging, and provide fallback behavior for production systems.
TOON is an emerging format with an open-source specification on GitHub (toon-format/toon). While not yet a formal standard like JSON (ECMA-404), it has growing adoption in AI/LLM workflows. The specification defines syntax rules, data types, conversion algorithms, and reference implementations. As LLM usage grows, TOON is gaining traction as a de facto standard for LLM-optimized data interchange, similar to how JSON emerged before standardization.
Yes, TOON works well for configuration files with repeated structures (microservices configs, feature flags, multi-environment settings). It's more concise than JSON for uniform arrays and more structured than YAML for tabular data. However, JSON and YAML have better IDE support, syntax highlighting, and validator tools. Use TOON if your configs have many uniform arrays, and stick with JSON/YAML for general-purpose configs with existing tooling.
The TOON ecosystem includes an official JavaScript/TypeScript parser and serializer on npm, online converters like this tool for quick transformations, a VS Code extension for syntax highlighting (in development), a Python library for data processing pipelines, and LLM integration examples for RAG and prompt engineering. The ecosystem is growing rapidly as AI developers discover TOON's efficiency benefits for LLM workflows.
Build AI agents that automatically convert JSON to TOON, optimize token usage in RAG pipelines, and reduce LLM API costs by 30-60%.