PHPackages                             toonphp/toon - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. toonphp/toon

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

toonphp/toon
============

PHP implementation of TOON (Token-Oriented Object Notation) – Compact serialization for LLM prompts.

0378↓12.5%PHP

Since Nov 7Pushed 6mo agoCompare

[ Source](https://github.com/tahir242/toonphp)[ Packagist](https://packagist.org/packages/toonphp/toon)[ RSS](/packages/toonphp-toon/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

TOON for PHP 🐘
==============

[](#toon-for-php-)

[![PHP Version](https://camo.githubusercontent.com/d6aac44f81cb2e6f4e71f098a1cb4a71992f24f7bfb424f6670db8313c9a855c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253545382e312d626c7565)](https://www.php.net/)[![License](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)](LICENSE)

PHP implementation of [TOON (Token-Oriented Object Notation)](https://github.com/toon-format/toon) – A lightweight, compact serialization format designed to reduce token usage in Large Language Model (LLM) prompts by 30-60% compared to JSON.

Features
--------

[](#features)

- 🎯 **30-60% token reduction** compared to JSON for LLM prompts
- 🔄 **100% lossless** round-trip compatibility with JSON-like structures
- 📊 **Tabular format** for uniform arrays of objects
- 🪶 **Lightweight** with zero runtime dependencies
- ✅ **PSR-12** code style compliant
- 📦 **PSR-4** autoloading
- 🧪 **Fully tested** with PHPUnit

What is TOON?
-------------

[](#what-is-toon)

TOON combines YAML-like indentation for nested objects with CSV-like tabular formats for uniform arrays, making it ideal for structured data transmission to LLMs. It eliminates unnecessary JSON syntax (brackets, quotes for simple strings, repeated keys) while maintaining human-readability.

### Example Comparison

[](#example-comparison)

**JSON (175 characters):**

```
{
  "users": [
    {"id": 1, "name": "Alice", "email": "alice@example.com"},
    {"id": 2, "name": "Bob", "email": "bob@example.com"}
  ]
}
```

**TOON (98 characters - 44% smaller):**

```
users:
  [2,]{id,name,email}:
    1,Alice,alice@example.com
    2,Bob,bob@example.com

```

Installation
------------

[](#installation)

Install via Composer:

```
composer require toonphp/toon
```

Usage
-----

[](#usage)

### Encoding (PHP Array → TOON)

[](#encoding-php-array--toon)

```
