π Announcing Toon v1.1.8!
Toon is the Laravel-native token-optimized object notation (TOON) library designed to convert PHP arrays and JSON into a compact, human-readable, AI-ready format. With v1.1.8, Toon now fully supports complex nested arrays, enabling developers to handle deep structures efficiently while saving tokens and maintaining readability.
β¨ Highlights of v1.1.8
-
inlineScalarnow recursively handles nested arrays - Fully compatible with structures like users, profiles, orders, and more
- Maintains TOON's compact, human-readable format
- Boosts AI prompt efficiency, reduces token usage, and lowers API costs
πΉ Example Usage
PHP Array
$data = [
'user' => [
'id' => 101,
'name' => 'Jane Developer',
'roles' => ['admin', 'editor'],
],
'orders' => [
[
'order_id' => 'ORD-1001',
'items' => [
['sku'=>'SKU-11','name'=>'Keyboard','qty'=>1,'price'=>1200],
['sku'=>'SKU-22','name'=>'Mouse','qty'=>2,'price'=>399],
],
'payment'=>['method'=>'upi','status'=>'paid','amount'=>1998],
],
],
];
TOON Output
user: id:101 name:Jane Developer roles: admin editor orders: items[1]{order_id,items,payment}: ORD-1001,0:sku:SKU-11,name:Keyboard,qty:1,price:1200,1:sku:SKU-22,name:Mouse,qty:2,price:399,method:upi,status:paid,amount:1998
Deeply nested arrays like
itemsare fully supported, making TOON perfect for AI prompts and complex data workflows.
πΉ Installation
composer require sbsaga/toon
- GitHub: https://github.com/sbsaga/toon
- Packagist: https://packagist.org/packages/sbsaga/toon
πΉ Why It Matters
- Reduces token usage by ~60-70% compared to JSON
- Keeps your data human-readable for debugging and logging
- Perfect for ChatGPT, Gemini, Claude, OpenAI, and other LLM integrations
- Maintains backward compatibility for existing TOON structures
πΉ Quick Tip
You can convert your arrays with:
$toon = Toon::convert($data);
$stats = Toon::estimateTokens($toon);
print_r($stats);
This will give you an estimate of the token savings while keeping data compact.
π‘ Pro Tip: Share your feedback, examples, or questions on the GitHub Discussions β your input drives the next improvements in TOON!
Experience token-efficient, readable AI-ready data now with Toon v1.1.8.
Top comments (0)