A lightweight, dependency-free PHP library for encoding & decoding TOON (Token-Oriented Object Notation).
TOON is a compact, human-readable, LLM-friendly data format β an alternative to JSON that uses indentation, lists, and tabular rows for intuitive structure.
This library provides a lite encoder + decoder, suitable for everyday PHP applications, config parsing, and AI-driven workflows.
-
Simple API:
Toon::encode()/Toon::decode() -
Full support for:
-
Nested objects via indentation
-
Primitive arrays:
tags[3]: php,ai,iot -
List arrays:
tags[2]: - php - ai -
Tabular arrays (
key[n]{a,b,c}:):items[2]{sku,qty,price}: A1,2,9.99 B2,1,14.5
-
-
Triple-quoted multiline strings
bio: """ I am Manoj. I love PHP. """ -
Minified TOON output (fully valid, no indentation)
(new EncodeOptions())->setMinify(true);
-
Complete test suite + round-trip stability checks
-
PHPStan clean (level 8)
-
Strict types everywhere
-
Zero dependencies
-
Detailed decode errors
- row count mismatches
- bad tabular rows
- invalid indentation
-
Comment support:
# comment// commentid: 1 # inline
Supports PHP 8.1 β 8.3
composer require manoj/toon-php-litegit clone git@github.com:manojrammurthy/toon-php-lite.git
cd toon-php-lite
composer install<?php
require __DIR__ . '/vendor/autoload.php';
use ToonLite\Toon;
$data = [
'id' => 1,
'name' => 'Manoj',
'tags' => ['php', 'ai', 'iot'],
'items' => [
['sku' => 'A1', 'qty' => 2, 'price' => 9.99],
['sku' => 'B2', 'qty' => 1, 'price' => 14.5],
],
];
$toon = Toon::encode($data);
echo $toon;
$decoded = Toon::decode($toon);
var_dump($decoded);id: 1
name: Manoj
tags[3]: php,ai,iot
items[2]{sku,qty,price}:
A1,2,9.99
B2,1,14.5
Encodes PHP values into valid TOON text.
['id' => 1, 'name' => 'Manoj']β
id: 1
name: Manoj
['php', 'ai', 'iot']β
tags[3]: php,ai,iot
['php', 'ai']β
tags[2]:
- php
- ai
[
['sku'=>'A1', 'qty'=>2, 'price'=>9.99],
['sku'=>'B2', 'qty'=>1, 'price'=>14.5],
]β
items[2]{sku,qty,price}:
A1,2,9.99
B2,1,14.5
"Hello\nWorld"β
bio: """
Hello
World
"""
$opts = (new EncodeOptions())->setMinify(true);
echo Toon::encode($data, $opts);Output:
id:1
name:"Manoj"
tags[3]:php,ai,iot
items[2]{sku,qty,price}:A1,2,9.99 B2,1,14.5
Parses TOON back into PHP:
- associative arrays
- numeric arrays
- ints, floats, strings, bool, null
- multiline strings
- tabular & list arrays
- nested objects based on indentation
# top-level comment
id: 1 # inline
// comment
name: Manoj
vendor/bin/phpunitcomposer phpstancomposer phpcs
composer php-cs-fixer- Multiline string support
- Minified output
- Strict decoder rewrite
- 100% PHPUnit coverage
- PHPStan level-8 clean
- EncodeOptions overhaul
- Object-level annotations
- TOON schema validation
- Streaming decoder (very large files)
- Official TOON conformance tests
- Error messages with line/column numbers
MIT Β© Manoj Ramamurthy