Weave Code
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.
make-dev/orca
dmstr/symfony-system-resources-bundle
dmstr/symfony-job-queue-bundle
dmstr/openapi-json-schema-bundle
dmstr/keycloak-security-bundle
dmstr/doctrine-audit-log-bundle
dmstr/api-platform-utils-bundle
dmstr/api-configuration-bundle
chrisdev/ux-components
baks-dev/finances
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle