Introducing TOON for Laravel β€” A Smarter, Token-Efficient Way to Talk to AI

🧠 TOON for Laravel β€” Compress your prompts, not your ideas

πŸ“ License: MIT Β Β 
⚑ Laravel: 9+   
🐘 PHP: 8.1+

✨ Why TOON?

When building AI-powered Laravel apps, developers often struggle with massive JSON data, expensive token usa…


This content originally appeared on DEV Community and was authored by Sagar Sunil Bhedodkar

🧠 TOON for Laravel β€” Compress your prompts, not your ideas

πŸ“ License: MIT Β Β 

⚑ Laravel: 9+   

🐘 PHP: 8.1+

✨ Why TOON?

When building AI-powered Laravel apps, developers often struggle with massive JSON data, expensive token usage, and hard-to-read prompts. That’s where TOON comes in β€” a Laravel-native data compressor designed to make your AI payloads smaller, cleaner, and easier to understand. πŸ’‘

"Compress your prompts, not your ideas."

TOON transforms verbose JSON or PHP arrays into a compact, human-readable format that reduces token cost by up to 70%, while preserving every bit of data.

πŸš€ Quick Overview

Feature Description
πŸ” Bidirectional Conversion Convert JSON ⇄ TOON effortlessly
🧩 Readable & Compact YAML-like syntax with improved readability
πŸ’° Token Efficient Save up to 70% of AI token costs
βš™οΈ Laravel Native Seamlessly integrates with facades, commands & service providers
πŸ“Š Built-in Analytics Analyze compression & token estimates
🧠 AI Ready Works perfectly with ChatGPT, Gemini, Claude & OpenAI APIs

🧠 What Makes TOON Different?

Unlike typical compression tools, TOON focuses on AI efficiency rather than binary storage. It’s designed for prompt engineering, where readability still matters. You can send structured data to your LLMs while keeping payloads light.

  • βœ… Human-friendly like YAML, but optimized for tokenization.
  • βœ… Built for Laravel developers β€” not just another JSON formatter.
  • βœ… 100% reversible β€” decode TOON back into JSON with no loss.

πŸ’» Installation & Setup

composer require sbsaga/toon

Once installed, TOON auto-registers its service provider and facade. Optionally, you can publish its config:

php artisan vendor:publish --provider="Sbsaga\\Toon\\ToonServiceProvider" --tag=config

Config File: config/toon.php

return [
    'enabled' => true,
    'escape_style' => 'backslash',
    'min_rows_to_tabular' => 2,
    'max_preview_items' => 200,
];

🧩 Convert JSON β†’ TOON

use Sbsaga\Toon\Facades\Toon;

$data = [
    'user' => 'Sagar',
    'message' => 'Hello, how are you?',
    'tasks' => [
        ['id' => 1, 'done' => false],
        ['id' => 2, 'done' => true],
    ],
];

echo Toon::convert($data);

Output:

user: Sagar
message: Hello\, how are you?
tasks:
  items[2]{done,id}:
    false,1
    true,2

πŸ”„ Convert TOON β†’ JSON

$toon = <<<TOON
user: Sagar
tasks:
  items[2]{id,done}:
    1,false
    2,true
TOON;

print_r(Toon::decode($toon));

πŸ“Š Real-World Benchmark

Metric JSON TOON Reduction
Size (bytes) 7,718 2,538 πŸ”» 67.12% smaller
Tokens (est.) 1,930 640 πŸ’Έ ~66.8% fewer tokens

πŸ’‘ Less data = fewer tokens = lower API bills. Simple math, massive savings.

JSON (7.7 KB)
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ

TOON (2.5 KB)
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ

πŸ§ͺ Quick Laravel Benchmark Route

use Illuminate\Support\Facades\Route;
use Sbsaga\Toon\Facades\Toon;

Route::get('/toon-benchmark', function () {
    $json = json_decode(file_get_contents(storage_path('app/users.json')), true);
    $toon = Toon::convert($json);

    return response()->json([
        'json_size' => strlen(json_encode($json)),
        'toon_size' => strlen($toon),
        'saving_percent' => round(100 - (strlen($toon) / strlen(json_encode($json)) * 100), 2),
        'toon_preview' => $toon,
    ]);
});

🧰 Artisan Commands

php artisan toon:convert storage/data.json
php artisan toon:convert storage/data.toon --decode
php artisan toon:convert storage/data.json --output=storage/result.toon

🌍 Real Use Cases

Use Case Benefit
πŸ€– AI Prompt Engineering Compress structured inputs for ChatGPT & Gemini
πŸ’¬ LLM Context Management Fit more data within token limits
🧾 Readable Logging Store structured data compactly
βš™οΈ Microservice Communication Reduce payload size across services

πŸ”‘ SEO & AI Integration Keywords

laravel, php, ai, chatgpt, openai, llm, gemini, mistral, anthropic, laravel-ai, laravel-openai, laravel-llm, php-ai, token-optimizer, prompt-engineering, api-optimization, backend-optimization, laravel-packages, php-development, web-development, json-compression, data-compression, efficient-coding, developer-tools, performance-optimization, api-integration, php-8.1

❀️ Final Thoughts

If you build AI tools with Laravel, TOON is a game-changer. It helps you:

  • πŸš€ Send more context without hitting token limits
  • 🧩 Keep your data clean, readable, and reversible
  • πŸ’Έ Save real money on AI API usage

🧠 β€œCompress your prompts, not your ideas.” β€” Let your code (and AI) breathe.

πŸ“¦ GitHub: https://github.com/sbsaga/toon

πŸ“¦ Packagist: https://packagist.org/packages/sbsaga/toon

Built with ❀️ for Laravel Developers who love clean, smart AI integrations.


This content originally appeared on DEV Community and was authored by Sagar Sunil Bhedodkar


Print Share Comment Cite Upload Translate Updates
APA

Sagar Sunil Bhedodkar | Sciencx (2025-11-08T20:35:50+00:00) Introducing TOON for Laravel β€” A Smarter, Token-Efficient Way to Talk to AI. Retrieved from https://www.scien.cx/2025/11/08/introducing-toon-for-laravel-a-smarter-token-efficient-way-to-talk-to-ai/

MLA
" » Introducing TOON for Laravel β€” A Smarter, Token-Efficient Way to Talk to AI." Sagar Sunil Bhedodkar | Sciencx - Saturday November 8, 2025, https://www.scien.cx/2025/11/08/introducing-toon-for-laravel-a-smarter-token-efficient-way-to-talk-to-ai/
HARVARD
Sagar Sunil Bhedodkar | Sciencx Saturday November 8, 2025 » Introducing TOON for Laravel β€” A Smarter, Token-Efficient Way to Talk to AI., viewed ,<https://www.scien.cx/2025/11/08/introducing-toon-for-laravel-a-smarter-token-efficient-way-to-talk-to-ai/>
VANCOUVER
Sagar Sunil Bhedodkar | Sciencx - » Introducing TOON for Laravel β€” A Smarter, Token-Efficient Way to Talk to AI. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/11/08/introducing-toon-for-laravel-a-smarter-token-efficient-way-to-talk-to-ai/
CHICAGO
" » Introducing TOON for Laravel β€” A Smarter, Token-Efficient Way to Talk to AI." Sagar Sunil Bhedodkar | Sciencx - Accessed . https://www.scien.cx/2025/11/08/introducing-toon-for-laravel-a-smarter-token-efficient-way-to-talk-to-ai/
IEEE
" » Introducing TOON for Laravel β€” A Smarter, Token-Efficient Way to Talk to AI." Sagar Sunil Bhedodkar | Sciencx [Online]. Available: https://www.scien.cx/2025/11/08/introducing-toon-for-laravel-a-smarter-token-efficient-way-to-talk-to-ai/. [Accessed: ]
rf:citation
» Introducing TOON for Laravel β€” A Smarter, Token-Efficient Way to Talk to AI | Sagar Sunil Bhedodkar | Sciencx | https://www.scien.cx/2025/11/08/introducing-toon-for-laravel-a-smarter-token-efficient-way-to-talk-to-ai/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.