Replacers let you transform data before TOON encoding without changing your original payload.
fn (array $path, string|int|null $key, mixed $value): mixed
Toon::skip() to remove a key or list itemuse 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;
});
$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;
});
$toon = Toon::encodeWith($payload, function (array $path, string|int|null $key, mixed $value) {
if ($path === ['meta'] && $key === 'trace') {
return Toon::skip();
}
return $value;
});
$toon = Toon::encodeWith($payload, function (array $path, string|int|null $key, mixed $value) {
if ($key === 'active') {
return $value ? 'yes' : 'no';
}
return $value;
});
$toon = toon_encode_with($payload, function (array $path, string|int|null $key, mixed $value) {
return $key === 'debug' ? \Sbsaga\Toon\Toon::skip() : $value;
});
encode()/convert() behavior is unchanged if you do not use replacers.How can I help you explore Laravel packages today?