This page explains where TOON helps most in production Laravel systems.
Problem:
Pattern:
use Sbsaga\Toon\Facades\Toon;
$context = [
'customer' => $customer->only(['id', 'name', 'tier']),
'orders' => $orders->map->only(['id', 'status', 'total'])->all(),
];
$prompt = "Review the context below and suggest next action.\n\n"
. Toon::promptBlock($context);
Why this works:
Problem:
Pattern:
use Illuminate\Support\Facades\Log;
use Sbsaga\Toon\Facades\Toon;
$safe = Toon::encodeWith($payload, function (array $path, string|int|null $key, mixed $value) {
if (in_array($key, ['password', 'token', 'secret'], true)) {
return Toon::skip();
}
return $value;
});
Log::info('webhook.snapshot', ['toon' => $safe]);
Why this works:
Problem:
Pattern:
php artisan toon:convert tests/fixtures/orders.json --encode --output=tests/fixtures/orders.toon
Why this works:
Problem:
Pattern:
use Sbsaga\Toon\Facades\Toon;
return response(Toon::encode($payload), 200)
->header('Content-Type', Toon::contentType());
Why this works:
decode()Problem:
Pattern:
use Sbsaga\Toon\Facades\Toon;
$raw = file_get_contents(storage_path('app/imports/data.toon'));
$result = Toon::validate($raw, true);
if (!$result['valid']) {
throw new RuntimeException($result['error'] ?? 'Invalid TOON');
}
$data = Toon::decode($raw);
Why this works:
Problem:
Pattern:
use Sbsaga\Toon\Facades\Toon;
logger()->warning('billing.job.failed', [
'job' => $jobId,
'context_toon' => Toon::encodeWith($context, fn (array $path, string|int|null $key, mixed $value) => $value),
]);
Why this works:
Choose TOON when:
Choose JSON when:
How can I help you explore Laravel packages today?