๐ŸŽ‰ NEW v2.4.1 - Latest AI Model Support!

Token-Optimized
Notation Language

A text-first, LLM-friendly serialization format.
Up to 50% fewer tokens than JSON. Zero dependencies. Built for the AI era.

Token Savings
Up to 60%
vs JSON
Performance
O(1)
Index Lookup
Optimization
10ร—
Strategies
Compatibility
100%
Backward

Real-World Token Comparison

Same data structure, dramatically different token costs

Dataset Size: users

Slide to see how token savings scale with data volume

Token Savings
1
JSON Format
100% baseline token usage
TONL Format WITH TYPES COMPACT

Type hints enabled (+20 tokens)

Type hints (u32, str, bool) add ~20 tokens but enable schema validation, TypeScript generation, and better LLM understanding. Still 32% smaller than JSON!

โ†“ 38%
(with types) (compact)
๐Ÿ’ฐ
Lower API Costs
saved per request
โšก
Fewer Tokens
tokens saved
NEW v2.4.1 Latest AI Model Support

๐ŸŽฎ Interactive Command Line

Experience the future of command-line data analysis with real-time visualization, theme support, and interactive features that make data analysis enjoyable.

tonl interactive
$ tonl stats package.json --interactive --theme neon
๐Ÿ“Š Analyzing file structure...
๐Ÿ“‹ INTERACTIVE DASHBOARD
๐Ÿ“ˆ Token Analysis (GPT-5) -47%
๐Ÿ”„ Switch Tokenizer
๐ŸŽจ Change Theme
๐Ÿ“Š File Comparison
Theme:
neon matrix cyberpunk

๐Ÿš€ Quick Start

npm install -g tonl
tonl stats data.json --interactive
๐ŸŽฏ

Menu-Driven Interface

Navigate easily through intuitive menus, use keyboard shortcuts for quick actions, and control your analysis with real-time progress tracking.

โšก

Live Tokenizer Switching

Switch instantly between GPT-5, Claude Sonnet 4.5, Gemini 2.5 Pro, Gemini 3 Pro, and Llama-4 tokenizers. Compare token costs for each model in real-time.

๐ŸŽจ

Multiple Theme Options

Choose from Neon, Matrix, Cyberpunk, and Default themes. Work with a visual experience that matches your personal preference.

๐Ÿ“Š

Side-by-Side Comparison

View JSON and TONL files side by side, track detailed compression metrics, and monitor cost analysis in real-time.

Powerful Features

More than just serialization - a complete data platform

v2.0 Complete Optimization Suite

10 advanced optimization strategies providing up to 60% additional compression beyond standard TONL encoding

๐ŸŽฏ 10 Strategies

Dictionary, Delta, RLE, Bit Packing, Column Reorder, Quantizer, Schema Inheritance, Hierarchical Grouping, Tokenizer Aware, Adaptive

๐Ÿ“ˆ 60% Savings

Additional compression beyond standard TONL with automatic strategy selection

๐Ÿš€ Zero Effort

One-line activation with automatic optimization

tonl encode data.json --optimize --verbose
๐Ÿ“ฆ

Compact Format

32-50% fewer tokens than JSON. Reduces LLM API costs with smart delimiter optimization.

users[2]{id,name}
๐Ÿ”

Query API

JSONPath-like queries with filters, wildcards, and recursive descent for powerful data extraction.

users[?(@.age > 18)]
โœ๏ธ

Modification

Full CRUD operations with change tracking, atomic saves, and rollback capabilities.

doc.set('user.age', 31)
โšก

High Performance

O(1) hash indices and O(log n) BTree indexes. 10-1600x faster than sequential scans.

<0.1ms lookup times
๐ŸŒŠ

Streaming Support

Process multi-gigabyte files with constant memory usage for large-scale data pipelines.

streamQuery('10GB.tonl')
โœ…

Schema Validation

Define schemas, validate data types, set constraints, and auto-generate TypeScript definitions.

age: u32 min:18 max:120
๐Ÿงญ

Tree Navigation

Traverse document trees, iterate collections, and search hierarchies with intuitive APIs.

doc.walk(visitor)
๐Ÿ“Š

Change Tracking

Track modifications with detailed diffs, timestamps, and rollback support for audit trails.

doc.getChanges()
๐Ÿ› ๏ธ

CLI Tools

Complete command-line toolkit for encoding, decoding, querying, validation, and formatting.

tonl encode --smart

Built for Real-World Applications

See how TONL solves common data challenges

๐Ÿค–

LLM Applications

Optimize your AI workflows with massive token savings and faster processing times.

  • Reduce prompt token costs by up to 50%
  • Fit more context within token limits
  • Human-readable format for debugging
  • Perfect for RAG pipelines and embeddings
๐Ÿ“ˆ

Data Analytics

Query and analyze large datasets with lightning-fast performance and SQL-like syntax.

  • Filter, sort, and aggregate data easily
  • Stream process multi-GB files efficiently
  • Build indexes for <0.1ms query times
  • Export results in any format needed
โš™๏ธ

Configuration Management

Store and manage application configs with human-readable format and validation.

  • Easier to read/edit than JSON or YAML
  • Schema validation ensures correctness
  • Track changes with built-in diff support
  • Generate TypeScript types automatically
๐Ÿ“Š

Log Processing

Stream 50GB+ log files with <100MB memory. Perfect for ETL pipelines.

๐Ÿงช

Testing Fixtures

Query test data easily. No database needed. Fast test execution.

๐Ÿ“ฆ

Data Migration

Track changes with diff engine. Rollback capability for safe migrations.

๐Ÿ”

API Caching

Compact cache storage with O(1) endpoint lookups and TTL support.

๐Ÿช

E-Commerce

Fast SKU lookups, price range queries with BTree indexing.

๐Ÿ“

CMS Content

Store articles, metadata. Query by tags, date ranges efficiently.

๐Ÿ”„

Data Versioning

Snapshots, complete history, detailed change tracking with timestamps.

โšก

Real-Time Apps

Efficient data sync. Change notifications. Fast queries for dashboards.

๐Ÿค– For LLM Developers

Teaching LLMs to Read TONL

Copy this prompt to enable any LLM to parse TONL data

System Prompt Template

Add this to your LLM system prompt when sending TONL data

The following data is in TONL format. Parse it as follows:

โ€ข Lines with [count]{fields}: are array headers, data rows follow
โ€ข Lines with {fields}: are object headers, field: value pairs follow
โ€ข Indentation (2 spaces) indicates nesting levels
โ€ข Default delimiter is comma unless #delimiter header specifies otherwise
โ€ข Type hints may appear: field:type (e.g., id:u32, name:str, active:bool)
  โ†’ Ignore the :type part, just parse the values
โ€ข Value types: unquoted numbers/booleans, quoted strings, null
โ€ข v2.0 Optimization: May contain #optimize directives (ignore these, they're metadata)

Examples:
Without types (compact):
users[2]{id,name,role}:
  1, Alice, admin
  2, Bob, user

With types (validation):
users[2]{id:u32,name:str,role:str}:
  1, Alice, admin
  2, Bob, user

With optimization (v2.0):
#optimize dictionary delta bitpack
users[2]{id:u32,name:str,role:str}:
  1, Alice, admin
  2, Bob, user

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

TONL v2.0 provides 60% additional compression while maintaining full LLM compatibility.

๐Ÿ’ก Pro tip: This prompt is ~180 tokens. Adding it to your system prompt is negligible compared to the 60-70% total savings with v2.0 optimization!

๐Ÿ“– Full Documentation

Detailed LLM integration guide with more examples and edge cases

View on GitHub

๐Ÿงช Try It Now

Test this prompt with real data in our interactive playground

Open Playground

Powerful API Examples

Real working code you can use today

Query Operations

// Filter users by condition
const admins = doc.query(
  'users[?(@.role == "admin")]'
);

// Get nested values
const names = doc.query(
  'users[*].name'
);

// Complex filters
const active = doc.query(
  'users[?(@.age > 25 && @.active)]'
);

// Array slicing
const first = doc.query('users[0:5]');

Modification Operations

// Update single value
doc.set('users[0].age', 32);

// Add new item
doc.push('users', {
  id: 1005,
  name: 'Eve Green'
});

// Delete item
doc.delete('users[3]');

// Get changes
const changes = doc.getChanges();

Performance Indexing

// Create hash index (O(1) lookup)
doc.createIndex('users', 'id', 'hash');

// Create BTree index (range queries)
doc.createIndex('users', 'age', 'btree');

// Ultra-fast indexed lookup
const user = doc.queryIndexed(
  'users',
  'id',
  1001
); // ~0.05ms

Streaming Large Files

// Stream process huge files
await streamQuery(
  'large.tonl',
  'users[?(@.active)]',
  (chunk) => {
    // Process each chunk
    console.log(chunk);
  }
);

// Constant memory usage
// Works with 10GB+ files

Performance Benchmarks

Real numbers from production workloads

Operation Speed Complexity Details
Parse/Decode ~1.2ms O(n) 1MB file, 10K records
Encode/Serialize ~0.8ms O(n) 1MB data, smart optimization
Hash Index Lookup ~0.05ms O(1) 10M records indexed
BTree Range Query ~0.3ms O(log n) 100K results from 10M
Sequential Scan ~45ms O(n) 10M records, no index
Stream Processing ~50MB/s O(1) memory Constant 10MB RAM usage
Modification ~0.1ms O(1) Single value update
File Save (Atomic) ~5ms O(n) 1MB file with fsync

Benchmark Environment: Node.js 20.x on Apple M1 Pro, 16GB RAM. Times shown are median of 1000 iterations. Hash index provides 10-1600x speedup over sequential scans for large datasets.

Complete CLI Toolkit

All commands you need for data operations

Encode
tonl encode data.json

Convert JSON to TONL format with smart optimization

Decode
tonl decode data.tonl

Convert TONL back to JSON format

Query
tonl query file.tonl

Execute JSONPath queries on TONL files

Validate
tonl validate --schema

Validate files against schema definitions

Format
tonl format file.tonl

Reformat files with specific delimiters

Stats
tonl stats --tokenizer

Compare token costs across LLM models

Generate Types
tonl generate-types

Auto-generate TypeScript type definitions

Help
tonl --help

View detailed help and usage examples

Example Workflow

# Convert JSON to TONL with optimization
tonl encode data.json --smart --stats

# Query for specific data
tonl query data.tonl 'users[?(@.age > 25)]' --output filtered.tonl

# Validate against schema
tonl validate filtered.tonl --schema user-schema.tonl

# Convert back to JSON
tonl decode filtered.tonl --out result.json

How TONL Compares

TONL vs other popular data formats

Feature TONL JSON CSV YAML
Token Efficiency 32-50% smaller Baseline N/A Similar to JSON
Nested Structures โœ… โœ… โŒ โœ…
Human Readable โœ… โœ… โœ… โœ…
Schema Validation โœ… Built-in Requires JSON Schema โŒ Limited
Query API โœ… JSONPath Library needed โŒ Library needed
Streaming Support โœ… O(1) memory Limited โœ… โŒ
Type System 8 types Dynamic Strings only Dynamic
LLM Optimized โœ… Primary goal โŒ โŒ โŒ
Change Tracking โœ… Built-in diff Library needed โŒ โŒ
Indexing (O(1) lookups) โœ… Hash + BTree โŒ โŒ โŒ

๐Ÿ† TONL's Unique Advantages

  • โ€ข Only format optimized specifically for LLM tokens
  • โ€ข Only format with built-in query + indexing
  • โ€ข Only format with streaming + O(1) memory
  • โ€ข Only format with integrated change tracking
  • โ€ข Zero dependencies - completely standalone
  • โ€ข 100% test coverage - production ready

Browser & TypeScript Ready

Works everywhere - Node.js, Browser, Deno, Bun

Browser (ESM)

<script type="module">
  import { encodeTONL, decodeTONL }
    from 'https://cdn.jsdelivr.net/npm/tonl@2.4.1/+esm';

  const data = { users: [{ id: 1, name: 'Alice' }] };
  const tonl = encodeTONL(data);
  console.log(tonl);
</script>
Bundle size: 6.32 KB gzipped

Browser (UMD)

<script src="https://unpkg.com/tonl@2.4.1/
  dist/browser/tonl.umd.js"></script>
<script>
  const tonl = TONL.encodeTONL({
    hello: "world"
  });
  console.log(tonl);
</script>
Bundle size: 4.53 KB gzipped

TypeScript - Full Type Safety

import { TONLDocument, encodeTONL, EncodeOptions } from 'tonl';

// Full IntelliSense support
const options: EncodeOptions = {
  includeTypes: true,
  delimiter: ',',
  indent: 2
};

const doc = TONLDocument.fromJSON<UserData>(data);
// Type-safe queries and modifications
const admins = doc.query('users[?(@.role == "admin")]');
โœ… Full type definitions included โœ… IntelliSense autocomplete โœ… TypeScript strict mode

Real Benchmark Results

Tested across 9 different data types

1.78-2.68x
Byte Compression
32-45% smaller files
1.62-1.87x
Token Compression
39-45% fewer LLM tokens
<7 KB
Browser Bundle
10x smaller than target

Tested Data Types

โœ“ User databases
โœ“ E-commerce products
โœ“ API responses
โœ“ App configurations
โœ“ Log entries
โœ“ Time series data
โœ“ Nested structures
โœ“ Social feeds
โœ“ Analytics data

All benchmarks run on Node.js 20.x, Apple M1 Pro, 16GB RAM. Results are median of 1000 iterations.

Implement in Any Language

Complete implementation guides and specifications available

๐Ÿ“˜
TypeScript
Official
๐Ÿ
Python
Guide Available
๐Ÿ”ต
Go
Guide Available
๐Ÿฆ€
Rust
Guide Available
โ˜•
Java
Guide Available

What You Get

  • Complete format specification
  • Parser implementation patterns
  • Encoder algorithm details
  • Test suite with 589 test cases
  • Query engine architecture
  • Schema validation examples

Why Choose TONL?

Built for production, designed for efficiency

๐Ÿ’ฐ

Massive Cost Savings

Save 32-50% on LLM API costs instantly. For apps processing millions of tokens daily, this translates to thousands of dollars saved monthly.

1M tokens/day ร— $0.03/1K = $30/day
With TONL: $18/day = $360/month saved
๐Ÿ›ก๏ธ

Zero Dependencies

Pure TypeScript implementation with no runtime dependencies. No supply chain risks, no version conflicts, no security vulnerabilities from third-party code.

0 deps 8.84KB Standalone
โšก

Blazing Fast Performance

Hash indexes provide O(1) lookups - 1600x faster than sequential scans. BTree indexes enable sub-millisecond range queries on millions of records.

<0.05ms
Hash lookup
<0.3ms
BTree range
โœ…

Fully Secure

791+ tests passing with 100% coverage. Advanced optimization system with 10 strategies. TypeScript strict mode. Semantic versioning. Comprehensive documentation. Used in production by multiple teams.

v2.4.1 Stable 791+ Tests TypeScript

Trusted by Developers Worldwide

Join teams building efficient AI applications

589
Tests Passing
100% coverage
0
Known Bugs
Production stable
25+
Live Examples
Interactive playground
100%
TypeScript
Fully typed
๐Ÿ’ฌ

"TONL has dramatically reduced our LLM API costs. We're processing the same amount of data but paying 32-50% less depending on the data structure. The query API is incredibly powerful, and the zero-dependency design means no supply chain risks."

E
Ersin Koc
Creator & Maintainer

Frequently Asked Questions

Everything you need to know about TONL

TONL eliminates JSON's redundant syntax like repeated key names, excessive quotes, and bracket nesting. It uses a table-like format where column names are declared once in a header, then data rows follow with just values. The smart encoder also chooses optimal delimiters (, | ; or tab) based on your data to minimize escaping.

Yes! TONL provides perfect round-trip conversion with JSON. You can encode JSON to TONL for LLM prompts (saving tokens), then decode back to JSON without any data loss. The CLI and API make integration seamless - just add tonl encode/decode steps to your pipeline.

Unlike CSV, TONL supports nested objects, arrays, multiple data types, and maintains type information. Unlike JSON, it's optimized for token efficiency. Unlike YAML, it has a formal specification and fast parsers.

TONL also includes powerful features CSV lacks: JSONPath queries, schema validation, indexing for performance, streaming support for huge files, and built-in modification APIs.

Absolutely! TONL v1.0+ is production-ready with 589 passing tests, zero known bugs, and stable APIs. It has zero runtime dependencies, comprehensive documentation, and follows semantic versioning. The TypeScript implementation is fully typed and includes extensive error handling. Many projects are already using it successfully.

Getting started is simple:

npm install tonl

Then import and use in your code, or use the CLI for quick conversions. Check out our documentation and interactive playground to learn more.

Yes! TONL is a text format that works with any LLM that accepts text input - OpenAI GPT, Anthropic Claude, Google Gemini, Meta Llama, etc. The format is designed to be LLM-friendly and human-readable. Token savings are consistent across all major tokenizers (tested with GPT-5, Claude Sonnet 4.5, Gemini 2.5 Pro, Gemini 3 Pro, and Llama 4).

Zero Dependencies โ€ข Fully Secure โ€ข MIT Licensed

Ready to Save Up to 50% on LLM Costs?

Join developers who are building smarter, more efficient AI applications with TONL

No credit card required
Free forever & open source
5 minute integration