asignua/filament-json-yaml-editor
A Filament form component for editing JSON and YAML values in admin panels. Adds an editor field for structured data, making it easier to manage configuration, metadata, and other JSON or YAML content from Filament resources and settings pages without switching tools.
composer require …) and, for the editor components, make sure the front-end assets are published/rebuilt — this release bumps the bundled esbuild to 0.28, so a stale published asset bundle will not pick up the new parser/format behaviour until you re-publish or re-run your asset build.YamlRule and JsonSchemaRule (including JsonSchemaRule::yaml()).JsonEditor and YamlEditor form components.Yaml facade (Yaml::parse(), Yaml::decodeToArrays()) is the low-level API; prefer the rules in request/form validation and only reach for the facade when you need the parsed payload for something other than validation.settings JSON/YAML column on a model, edited in a form, validated on save.// app/Models/Setting.php
protected $casts = ['payload' => 'array'];
// app/Http/Requests/UpdateSettingsRequest.php
public function rules(): array
{
return [
'payload' => ['required', new YamlRule()], // YAML input
// or, when the source is JSON Schema:
// 'payload' => ['required', JsonSchemaRule::yaml($schema)],
];
}
'array' (built-in or a custom cast, including nested field names) is the expected storage shape; the JsonEditor/YamlEditor components read and write through it. A top-level string accidentally stored by an array cast ("123", "hello", a: b) is now shown as JSON/YAML text and saved back as the same string — handy for legacy rows, but don't rely on it as a design: it means a scalar can round-trip through a field you thought was an array.YamlRule (or JsonSchemaRule::yaml($schema)) on the raw textarea value, then decode into the array cast. Keep the raw string out of the model; validate → Yaml::decodeToArrays() → assign.JsonSchemaRule with opis/json-schema is the pattern for user-authored config: you get up to maxErrors() messages back, and an unresolvable $ref or a malformed schema keyword now surfaces as a validation error rather than a 500 — so bad schema shipped by an admin is a fixable form error, not an outage. Still wrap schema loading itself (file/DB fetch) in your own error handling.Format button only re-indents. Big integers, 1.0, duplicate keys and key order survive untouched. If you were relying on "Format" to normalise stored config (dedupe keys, coerce floats), do that server-side before comparing/diffing.!!set or other non-core tags, resolve them before they reach the parser (pre-process to plain maps) — the bundled js-yaml 5 rejects them by default.$config['released_at']->format(...) on a parsed value must cast explicitly (Carbon::parse($value)).!!set and friends no longer parse by default. This will bite on imported YAML from other toolchains.2024-12-25: x) now stay strings instead of becoming unix timestamps — good for config maps keyed by date. But note the documented gap: a date key inside a flow map ({2024-01-01: a}) is still rejected unless you pass PARSE_DATETIME. Use block style, or quote the key.: | does not start a block scalar; a quote after a spaced -, : or ? inside plain text no longer opens a scalar. Remove any defensive quoting hacks you added for these.Yaml::parse(), Yaml::decodeToArrays(), YamlRule, JsonSchemaRule::yaml()). If you bypass the facade and call a parser directly, you lose that protection — route untrusted YAML through the package.$& / $' in a message no longer corrupts it. When reporting errors to users, log the raw message too; the on-screen line is display-safe but still terse.maxErrors() bounds JsonSchemaRule output — tune it down for end-user forms (avoids a wall of red) and up in tests where you assert on all failures.DateTime/Carbon assumptions on parsed YAML, grep for !! tags in fixtures, and re-run any test that asserted on Format-normalised output.How can I help you explore Laravel packages today?