v1.0.7 - Enhanced Token Optimization

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
Tests Passing
496
โœ“ 100%
Dependencies
0
Pure TS
Gzipped Size
8.84
KB

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

Powerful Features

More than just serialization - a complete data platform

๐Ÿ“ฆ

Compact Format

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

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

Query API

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

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

Modification

Full CRUD operations with change tracking, atomic file saves, and rollback capabilities for safe edits.

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

High Performance

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

<0.1ms lookup times
๐ŸŒŠ

Streaming Support

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

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

Schema Validation

Define schemas, validate data types, set constraints, and auto-generate TypeScript type definitions. Toggle "Show Types" above to see type hints.

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

Tree Navigation

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

doc.walk(visitor)
๐Ÿ“Š

Change Tracking

Track all 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 operations.

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

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

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

๐Ÿ’ก Pro tip: This prompt is ~150 tokens. Adding it to your system prompt is negligible compared to the 32-50% savings on your data!

๐Ÿ“– 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@1.0.7/+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@1.0.7/
  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 496 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

496 tests passing with 100% coverage. TypeScript strict mode. Semantic versioning. Comprehensive documentation. Used in production by multiple teams.

v1.0.7 Stable 494 Tests TypeScript

Trusted by Developers Worldwide

Join teams building efficient AI applications

496
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 496 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 3.5, Gemini 2.0, 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