Download the PHP package mateuszkardas/toon without Composer
On this page you can find all versions of the php package mateuszkardas/toon. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mateuszkardas/toon
More information about mateuszkardas/toon
Files in mateuszkardas/toon
Package toon
Short Description PHP implementation of Token-Oriented Object Notation (TOON) - A compact, human-readable serialization format designed for LLM input
License MIT
Homepage https://github.com/mateuszkardas/toon-php
Informations about the package toon
TOON (Token-Oriented Object Notation) - PHP Implementation
Note: This is a PHP implementation based on the original TOON format specification and reference implementations from toon-format/toon
PHP implementation of Token-Oriented Object Notation (TOON), a compact, human-readable serialization format designed for passing structured data to Large Language Models with significantly reduced token usage.
TOON is intended for LLM input, not output. It's particularly efficient for uniform arrays of objects โ multiple fields per row, same structure across items.
Features
- ๐ธ Token-efficient: typically 30โ60% fewer tokens than JSON
- ๐คฟ LLM-friendly guardrails: explicit lengths and fields enable validation
- ๐ฑ Minimal syntax: removes redundant punctuation (braces, brackets, most quotes)
- ๐ Indentation-based structure: like YAML, uses whitespace instead of braces
- ๐งบ Tabular arrays: declare keys once, stream data as rows
- โ Full compatibility: Implements the TOON v1.3 specification
Installation
Install via Composer:
Quick Start
Why TOON?
AI is becoming cheaper and more accessible, but larger context windows allow for larger data inputs as well. LLM tokens still cost money โ and standard JSON is verbose and token-expensive:
TOON conveys the same information with fewer tokens:
API Reference
Encoding
Convert a PHP value to TOON format.
Options:
indent(int): Number of spaces per indentation level (default: 2)delimiter(string): Delimiter for arrays (',' '|' or "\t") (default: comma)lengthMarker(string): Optional marker to prefix array lengths ("#" or "") (default: empty)
Example:
Decoding
Convert TOON format to a PHP value.
Options:
indent(int): Number of spaces per indentation level (default: 2)strict(bool): Enforce strict validation (default: true)
Example:
Convenience Methods
Format Overview
Primitives
Objects (Nested)
Arrays (Inline)
Arrays (Tabular) - Most Efficient
Arrays (List)
String Escaping
TOON properly escapes special characters:
Custom Delimiters
Length Markers
Examples
See the /examples directory for more comprehensive examples:
examples/basic.php- Basic usage examplesexamples/advanced.php- Advanced features and use cases
Run examples:
Requirements
- PHP 8.1 or higher
Testing
Notes and Limitations
- For LLM input only: TOON is optimized for human-to-LLM communication, not LLM output
- Best for tabular data: Maximum efficiency with uniform arrays of objects
- Deeply nested data: JSON may be more efficient for complex nested structures
- Empty arrays: Treated as empty objects
[]in the round-trip
Use Cases
- Passing large datasets to LLMs (GPT, Claude, etc.)
- Reducing token costs in AI applications
- Serializing tabular data for prompts
- Configuration files for AI agents
- Data exchange in token-constrained environments
Related Projects
- toon-format/toon - Original TypeScript/JavaScript implementation
- toon-format/spec - TOON format specification
- mateuszkardas/toon-go - Go implementation
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT License - see LICENSE file for details.
Author
Mateusz Kardaล
- GitHub: @mateuszkardas
- Repository: https://github.com/mateuszkardas/toon-php
Acknowledgments
Based on the TOON format specification and reference implementation by the toon-format team.