Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Toon Laravel Package

sbsaga/toon

View on GitHub
Deep Wiki
Context7

Replacer Recipes

Replacers let you transform data before TOON encoding without changing your original payload.

Signature

fn (array $path, string|int|null $key, mixed $value): mixed
  • return Toon::skip() to remove a key or list item
  • return any other value to keep/transform it

Basic Usage

use Sbsaga\Toon\Facades\Toon;

$toon = Toon::encodeWith($payload, function (array $path, string|int|null $key, mixed $value) {
    if ($key === 'debug') {
        return Toon::skip();
    }

    return $value;
});

Recipe: Redact Secrets

$toon = Toon::encodeWith($payload, function (array $path, string|int|null $key, mixed $value) {
    if (in_array($key, ['email', 'token', 'api_key'], true)) {
        return '[redacted]';
    }

    return $value;
});

Recipe: Remove Internal Branches by Path

$toon = Toon::encodeWith($payload, function (array $path, string|int|null $key, mixed $value) {
    if ($path === ['meta'] && $key === 'trace') {
        return Toon::skip();
    }

    return $value;
});

Recipe: Normalize Scalars

$toon = Toon::encodeWith($payload, function (array $path, string|int|null $key, mixed $value) {
    if ($key === 'active') {
        return $value ? 'yes' : 'no';
    }

    return $value;
});

Helper Variant

$toon = toon_encode_with($payload, function (array $path, string|int|null $key, mixed $value) {
    return $key === 'debug' ? \Sbsaga\Toon\Toon::skip() : $value;
});

Notes

  • The replacer is called recursively for nested values.
  • Skipping at root level returns an empty TOON string.
  • Existing encode()/convert() behavior is unchanged if you do not use replacers.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
abbasudo/artisan-route
mirvan/ippanel
ignibyte/aic-framework
glavweb/data-schema-bundle
glavweb/datagrid-bundle
tacticmedia/scim-server
uni-method/frame
neika-ai/sdk
adachsoft/php-code-style
pharaonic/laravel-notification-dependencies
beautinow/translug
dev-brainiac/bot-cloaked
octoberrain/html
octoberrain/extension
octoberrain/exception
octoberrain/contracts
adachsoft/api-version-bundle
cgv/localized-resource
noith/settings
kda/laravel-package