- Регистрация
- 9 Май 2015
- Сообщения
- 1,605
- Баллы
- 155
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.
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."Compress your prompts, not your ideas."
| Feature | Description |
|---|---|
| Convert JSON ⇄ TOON effortlessly | |
| YAML-like syntax with improved readability | |
| Save up to 70% of AI token costs | |
| Seamlessly integrates with facades, commands & service providers | |
| Analyze compression & token estimates | |
| Works perfectly with ChatGPT, Gemini, Claude & OpenAI APIs |
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.
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,
];
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
$toon = <<<TOON
user: Sagar
tasks:
items[2]{id,done}:
1,false
2,true
TOON;
print_r(Toon::decode($toon));
| Metric | JSON | TOON | Reduction |
|---|---|---|---|
| Size (bytes) | 7,718 | 2,538 | |
| Tokens (est.) | 1,930 | 640 |
JSON (7.7 KB)
██████████████████████████████████████████████████████████████████████████
TOON (2.5 KB)
█████████████████
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,
]);
});
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
| Use Case | Benefit |
|---|---|
| Compress structured inputs for ChatGPT & Gemini | |
| Fit more data within token limits | |
| Store structured data compactly | |
| Reduce payload size across services |
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
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.
Built with
Источник: