DEV Community

Cover image for Toon 1.1.8 β€” Unlock Complex Nested Array Support for Laravel
Sagar Sunil Bhedodkar
Sagar Sunil Bhedodkar

Posted on

Toon 1.1.8 β€” Unlock Complex Nested Array Support for Laravel

πŸš€ 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

  • inlineScalar now 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],
        ],
    ],
];
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Deeply nested arrays like items are fully supported, making TOON perfect for AI prompts and complex data workflows.

πŸ”Ή Installation

composer require sbsaga/toon
Enter fullscreen mode Exit fullscreen mode

πŸ”Ή 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);
Enter fullscreen mode Exit fullscreen mode

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)