TONL
A text-first, LLM-friendly serialization format that reduces token consumption by up to 50% compared to JSON while supporting advanced features like schema validation and high-performance querying.
TONL (Token-Optimized Notation Language) is a specialized serialization format designed for the AI era, focusing on maximizing token efficiency when communicating with Large Language Models. Created to address the overhead of JSON, it achieves 32-50% fewer tokens by utilizing a compact, table-like structure that avoids redundant keys and excessive punctuation. The format is designed to be human-readable while maintaining full compatibility with existing JSON workflows through seamless round-trip conversion.
The functionality centers on a document-based data model supporting primitives, objects, and arrays. By declaring field names once in headers and utilizing delimiter-separated data rows, TONL significantly reduces the total payload size required for LLM prompts. This makes it an ideal choice for RAG pipelines, context-heavy AI tasks, and data-intensive applications where API costs and token limits are critical constraints. The format is supported by a robust TypeScript implementation with zero runtime dependencies, ensuring security and stability.
Some of the key features are:
- Token Optimization: Reduces LLM token consumption by 32-50% compared to standard JSON.
- Smart Encoding: Uses 10 advanced strategies, including dictionary, delta, and run-length encoding, to achieve up to 60% additional compression.
- Integrated Query API: Includes JSONPath-like query capabilities, allowing for filtering, aggregation, and recursive descent without needing external libraries.
- High Performance Indexing: Provides O(1) hash indices and O(log n) BTree indexes for sub-millisecond data lookups.
- Schema Validation: Offers built-in schema definition, type constraints, and auto-generation of TypeScript definitions.
- Streaming Support: Enables constant-memory processing for multi-gigabyte files, making it suitable for large-scale data pipelines.
- Change Tracking: Includes native support for tracking modifications, diff generation, and rollback functionality.
- CLI Toolkit: Offers a complete interactive dashboard with real-time tokenizer comparisons, theme support, and batch conversion capabilities.
TONL is used by integrating it into existing workflows via the provided CLI or native API. Developers can convert JSON data to TONL before sending it to an LLM by including a system prompt template that instructs the model on how to parse the header-and-row structure. In production environments, it functions as a drop-in replacement for JSON, providing the same hierarchical structure but with optimized throughput and storage characteristics.
Some common use cases include:
- LLM Prompt Engineering: Significantly reducing prompt token counts for chat or analysis applications.
- Log Processing: Streaming large-scale logs in ETL pipelines with minimal memory overhead.
- Configuration Management: Storing application settings with validation and human-readable formatting.
- API Caching: Reducing storage footprint for cached API responses while maintaining O(1) retrieval speeds.
- Data Analytics: Filtering and aggregating large, structured datasets in-memory or on-disk with high performance.
Comments
0Markdown is supported.