64robots/nova-json
64robots/nova-json provides a JSON field for Laravel Nova, making it simple to view and edit JSON attributes directly within your admin panel. It offers a clean, developer-friendly way to manage structured data on Nova resources without building custom field components.
Treat 64robots/nova-json as a small Nova form/detail field for editing JSON stored on a model. It is archived, so first verify that its Nova/Laravel constraints match your app before adopting it. It does not replace model casts, migrations, or validation.
Minimal setup:
Confirm compatibility before installing:
composer.json for Nova, Laravel, and PHP constraints.Add a JSON-capable column if you do not already have one:
Schema::table('projects', function (Blueprint $table) {
$table->json('settings')->nullable();
});
protected $casts = [
'settings' => 'array',
];
use R64\NovaJson\NovaJson;
public function fields(Request $request)
{
return [
NovaJson::make('Settings')
->rules('nullable', 'json')
->hideFromIndex(),
];
}
Where to look first:
src/NovaJson.php or the main field class for resolve, fill, and default behavior.resources/js to understand whether it expects a JSON string or an already-decoded array.composer.json for Nova compatibility.First useful use case: a settings, metadata, or payload column on a resource. Use the field for occasional admin edits, hide it from index views, and keep normal application reads/writes on the model cast rather than on the Nova field.
Use the Nova field as an editing surface, not as your application’s JSON layer. Keep encoding, decoding, defaults, and validation in the model/domain layer so API and Nova behavior stay consistent.
Basic resource pattern:
use R64\NovaJson\NovaJson;
public function fields(Request $request)
{
return [
NovaJson::make('Settings')
->rules('nullable')
->hideFromIndex()
->help('Enter a JSON object, for example: {"theme":"dark"}'),
];
}
Pair it with a model cast:
protected $casts = [
'settings' => 'array',
];
If the field expects a raw string but your model cast returns an array, do not blindly add another json_encode. Inspect the field’s resolve/fill methods first. Double-encoding is a common failure mode with JSON Nova fields.
Validation pattern: validate syntax and shape separately. The Laravel json rule checks syntax only; it does not enforce that the payload is an object, has required keys, or uses allowed types.
NovaJson::make('Settings')
->rules([
'nullable',
function ($attribute, $value, $fail) {
if ($value === null || $value === '') {
return;
}
$json = is_array($value) ? json_encode($value) : $value;
$decoded = json_decode($json, true);
if (json_last_error() !== JSON_ERROR_NONE) {
return $fail('Settings must be valid JSON: '.json_last_error_msg());
}
if (! is_array($decoded)) {
$fail('Settings must decode to a JSON object or array.');
}
if (array_key_exists('theme', $decoded) && ! is_string($decoded['theme'])) {
$fail('The theme value must be a string.');
}
},
])
->hideFromIndex();
Recommended workflows:
hideFromIndex() for large JSON so index requests and tables stay fast.onlyOnDetail() or readonly() for audit/history views.null, '', or {}. Do not let different screens produce different empties.text instead of native json, or when the package expects a different representation than your cast.$model->settings as an array via the cast, not by decoding raw request values.If you need to customize behavior, prefer a small subclass or custom validation rule over editing vendor files:
class ProjectSettingsJson extends NovaJson
{
public function resolve($resource, $attribute = null)
{
parent::resolve($resource, $attribute);
// Normalize null/empty values for the form here if needed.
}
}
json_encode in a mutator can store a JSON string containing JSON. Inspect the stored value directly in the database.null, '', '{}', and '[]' are not interchangeable. Validation and application code should agree on what empty means.json rules only prove syntax. Use custom rules for required keys, allowed types, nested structure, and size limits.text/longText. Confirm how your database stores and returns the value before assuming the field sees a string.resolve/fill behavior, the model cast, and the raw database value. Log json_last_error_msg() when decoding fails.Textarea with JSON validation, or a small custom field built for your Nova version, is often safer than keeping an archived dependency.How can I help you explore Laravel packages today?