Download the PHP package iamgerwin/toon-php without Composer
On this page you can find all versions of the php package iamgerwin/toon-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download iamgerwin/toon-php
More information about iamgerwin/toon-php
Files in iamgerwin/toon-php
Package toon-php
Short Description A lightweight, fast, and feature-rich TOON (Token-Oriented Object Notation) library for PHP - optimized for LLM contexts with 30-60% token savings
License MIT
Homepage https://github.com/iamgerwin/toon-php
Informations about the package toon-php
TOON PHP
Stop wasting tokens. Start saving money.
A lightweight, blazing-fast TOON (Token-Oriented Object Notation) library for PHP that cuts your LLM API costs by 30-60%. Because every token counts when you're building AI applications.
Why TOON?
Traditional JSON is expensive for AI applications. Every {, }, [, ], and " counts as a token. TOON eliminates this waste while maintaining perfect readability.
Real-World Performance
Based on official TOON benchmarks:
| Use Case | JSON Tokens | TOON Tokens | Savings |
|---|---|---|---|
| E-commerce Orders | 3,245 | 2,170 | 33.1% |
| User Lists | 150 | 82 | 45.3% |
| Product Catalogs | 320 | 180 | 43.8% |
| Event Logs | 1,890 | 1,606 | 15.0% |
| Config Files | 2,456 | 1,687 | 31.3% |
Cost Impact
At OpenAI's GPT-4 pricing ($0.03/1K tokens):
- 1M API calls with 100 tokens each = $3,000 (JSON) → $1,500 (TOON)
- Annual savings: $1,500+ for moderate usage
- ROI: Immediate (zero migration cost)
Installation
Requirements:
- PHP 8.1+ (v2.x - Recommended, Latest & Default)
- PHP 7.0-8.0 (v1.x - Legacy Support)
Quick Start
Powerful Features
🎯 Tabular Format for Arrays
Perfect for uniform datasets:
73.9% retrieval accuracy vs 70.7% for JSON in LLM benchmarks (source).
⚡ Multiple Encoding Modes
🔍 Token Analysis
🎨 Complete Type Support
Helper Functions
When to Use TOON
✅ Perfect For:
- LLM API calls (ChatGPT, Claude, Gemini)
- AI agent communication
- Prompt engineering (system prompts, context)
- Chatbot memory (conversation history)
- Training data (uniform datasets)
- Cost-sensitive applications
⚠️ Consider JSON When:
- Building public REST APIs
- Need universal ecosystem support
- Working with deeply nested structures (>5 levels)
Benchmarks
Independent tests show TOON's advantages:
Token Efficiency
- Average savings: 30-60% vs JSON
- Best case: 62% reduction (flat tabular data)
- Worst case: 15% reduction (semi-structured data)
LLM Retrieval Accuracy
Tested across 209 questions on 4 LLM models:
- TOON: 73.9% accuracy | 2,744 tokens
- JSON (compact): 70.7% accuracy | 3,081 tokens
- JSON (formatted): 69.7% accuracy | 4,545 tokens
TOON achieves +3.2% better accuracy while using 39.6% fewer tokens (source).
Processing Speed
- Faster tokenization (less overhead)
- Improved throughput (smaller payloads)
- Better context utilization (more data in context window)
Advanced Usage
Strict vs Lenient Decoding
Custom Delimiters
Quality Assurance
This package maintains the highest quality standards:
- ✅ PHPStan Level 6 (strict static analysis)
- ✅ PSR-12 code style compliance
- ✅ 100% test coverage (29 tests, 63 assertions)
- ✅ Zero dependencies (pure PHP)
- ✅ Continuous Integration (GitHub Actions)
- ✅ Multi-version testing (PHP 8.1-8.4)
Real-World Example
Migration from JSON
Zero-effort migration:
Contributing
Contributions are welcome! This package follows:
- PSR-12 coding standards
- Semantic Versioning
- Conventional Commits
Versioning
This library follows Semantic Versioning with separate branches for different PHP versions:
- v2.x (main branch): PHP 8.1-8.4 with modern features - Latest & Default
- v1.x (legacy branch): PHP 7.0-8.0 compatibility - Legacy Support
Version 2.x is the recommended and default version for new projects. Composer will automatically select v2.x for PHP 8.1+ installations and v1.x for PHP 7.0-8.0 installations.
Branches
- main → v2.x (PHP 8.1+) - Active development, latest features
- legacy → v1.x (PHP 7.0-8.0) - Bug fixes only, no new features
Installation by PHP Version
Feature Differences
| Feature | v2.x (PHP 8.1+) | v1.x (PHP 7.0-8.0) |
|---|---|---|
| TOON Encoding/Decoding | ✅ | ✅ |
| DateTime Support | ✅ | ✅ |
| Enum Support | ✅ | ❌ (PHP 8.1+ only) |
| Tabular Format | ✅ | ✅ |
| Helper Functions | ✅ | ✅ |
| PHPStan Analysis | Level 6 | Level 6 |
| Test Coverage | 29 tests | 32 tests |
License
MIT License - see LICENSE.md
Credits
- Built with ❤️ for the PHP and AI community
- TOON format: toon-format/toon
- Inspired by the need to make AI more accessible through cost reduction
Stop paying for redundant tokens. Start using TOON PHP.
See Examples