sbsaga/toon

🧠 TOON for Laravel β€” a compact, human-readable, and token-efficient data format for AI prompts & LLM contexts. Perfect for ChatGPT, Gemini, Claude, Mistral, and OpenAI integrations (JSON ⇄ TOON).

Installs: 14

Dependents: 0

Suggesters: 0

Security: 0

Stars: 6

Watchers: 0

Forks: 3

Open Issues: 0

pkg:composer/sbsaga/toon

v1.1.4 2025-11-02 10:39 UTC

This package is auto-updated.

Last update: 2025-11-09 18:27:37 UTC


README

Compact Β· Token-Efficient Β· Human-Readable Data Format for AI Prompts & LLM Contexts

TOON Logo

Latest Version on Packagist Total Downloads License: MIT Laravel 9+ PHP 8.1+ AI Ready

πŸ“š Table of Contents

  1. Overview
  2. Key Features
  3. Benchmark & Analytics
  4. Installation
  5. Configuration
  6. Usage
  7. Quick Benchmark Route
  8. Analytics & Visualization
  9. CLI Commands
  10. Integration Use Cases
  11. Compatibility
  12. Compression Visualization
  13. SEO & AI Integration Keywords
  14. License

✨ Overview

TOON for Laravel β€” also known as Token-Optimized Object Notation β€” is a Laravel-native AI data optimization library that transforms large JSON or PHP arrays into a compact, readable, and token-efficient format.

It’s crafted for developers working with ChatGPT, Gemini, Claude, Mistral, or OpenAI APIs, helping you:
βœ… Save tokens and reduce API costs
βœ… Simplify complex prompt structures
βœ… Improve AI response quality and context understanding
βœ… Maintain human readability and reversibility

πŸ’¬ β€œCompress your prompts, not your ideas.”

πŸš€ Key Features

Feature Description
πŸ” Bidirectional Conversion Convert JSON ⇄ TOON with ease
🧩 Readable & Compact YAML-like structure, human-friendly format
πŸ’° Token-Efficient Save up to 70% tokens on every AI prompt
βš™οΈ Seamless Laravel Integration Built with Facades, Service Providers, and Artisan commands
πŸ”’ Preserves Key Order Ensures deterministic data output
πŸ“Š Built-in Analytics Measure token, byte, and compression performance
🌍 AI & LLM Ready Optimized for ChatGPT, Gemini, Claude, and Mistral models

πŸ§ͺ 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

πŸ“ˆ Visual Comparison

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

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

πŸ’‘ TOON reduces token load by 60–75%, improving AI efficiency, cost, and response quality.

βš™οΈ Installation

composer require sbsaga/toon

Laravel automatically discovers the Service Provider and Facade.

βš™οΈ Configuration

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

Creates a configuration file at config/toon.php:

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

🧠 Usage

➀ 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],
    ],
];

$converted = Toon::convert($data);
echo $converted;

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;

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

➀ Estimate Tokens

$stats = Toon::estimateTokens($converted);
print_r($stats);

Output:

{
  "words": 20,
  "chars": 182,
  "tokens_estimate": 19
}

πŸ§ͺ Quick 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);
    $jsonEncoded = json_encode($json, JSON_PRETTY_PRINT);
    $toonEncoded = Toon::convert($json);

    return response()->json([
        'json_size_bytes' => strlen($jsonEncoded),
        'toon_size_bytes' => strlen($toonEncoded),
        'saving_percent' => round(100 - (strlen($toonEncoded) / strlen($jsonEncoded) * 100), 2),
        'json_content' => $jsonEncoded,
        'toon_content' => $toonEncoded,
    ]);
});

πŸ“Š Analytics & Visualization

Metric Description Example
json_size_bytes Original JSON size 7,718
toon_size_bytes Optimized TOON size 2,538
saving_percent Space saved 67.12%
tokens_estimate Estimated token count 640
compression_ratio Ratio (TOON/JSON) 0.33

🧠 Visual Graph (Efficiency Comparison)

| JSON: β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ 100%
| TOON: β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ 33%

🧰 Artisan Commands

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

🧩 Integration Use Cases

Use Case Benefit
πŸ€– AI Prompt Engineering Compress structured data for ChatGPT / LLMs
πŸ“‰ Token Optimization Reduce token usage and API costs
🧠 Data Preprocessing Streamline complex structured inputs
🧾 Logging & Debugging More human-readable than JSON
πŸ” Developer Tools Perfect for previews and compact dashboards

🧰 Compatibility

Laravel PHP Package Version
9.x – 12.x β‰₯ 8.1 v1.1.0+

πŸ“‰ Example Compression Visualization

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

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

🧠 ~67% size reduction while retaining complete data accuracy.

🌐 SEO & AI Integration Keywords

Keywords:
laravel ai, ai for laravel, chatgpt laravel, laravel chatgpt, gemini laravel, laravel gemini, laravel anthropic, laravel mistral, laravel openai, openai laravel, laravel llm, llm laravel, ai laravel package, prompt compression, token optimizer, laravel json formatter, compact notation, laravel data compressor, token saver, laravel ai integration, sbsaga toon, laravel-toon, toon php, laravel ai toolkit, openai cost optimizer, laravel ai efficiency, chatgpt laravel toolkit, ai-ready laravel package.

πŸ’‘ Contribution

Contributions are highly encouraged!

  • Fork the repository
  • Create a new feature branch
  • Commit & push improvements
  • Submit a Pull Request πŸŽ‰

πŸ“œ License

Licensed under the MIT License β€” free for both commercial and personal use.

🧠 β€œCompress your prompts, not your ideas.” β€” TOON helps you talk to AI efficiently.