PHPackages                             codehero-mx/nova-json-wrapper - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. codehero-mx/nova-json-wrapper

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

codehero-mx/nova-json-wrapper
=============================

Allows you to group Nova fields and merge their output into a single JSON column.

1.1.0(3mo ago)020↓77.8%MITPHPPHP ^8.2

Since Mar 19Pushed 3mo agoCompare

[ Source](https://github.com/codehero-mx/nova-json-wrapper)[ Packagist](https://packagist.org/packages/codehero-mx/nova-json-wrapper)[ RSS](/packages/codehero-mx-nova-json-wrapper/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (2)Dependencies (1)Versions (3)Used By (0)

Nova Json Wrapper
=================

[](#nova-json-wrapper)

[![Latest Version on Packagist](https://camo.githubusercontent.com/daadf2efadc9d49f5130ba5daa10273d362a4326d78e3d9445a2544a7b4a08a3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636f64656865726f2d6d782f6e6f76612d6a736f6e2d77726170706572)](https://packagist.org/packages/codehero-mx/nova-json-wrapper)[![Total Downloads](https://camo.githubusercontent.com/fbf2eaff5dcd9a07cac017ea2f3719fd8a15ab19f11501d0b9d4351ec3e394c2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636f64656865726f2d6d782f6e6f76612d6a736f6e2d77726170706572)](https://packagist.org/packages/codehero-mx/nova-json-wrapper)[![License](https://camo.githubusercontent.com/63b4503f179365f623088499891e042b63307a26a535e4bd2cf6b94ad89862c5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f636f64656865726f2d6d782f6e6f76612d6a736f6e2d77726170706572)](https://github.com/codehero-mx/nova-json-wrapper/blob/master/LICENSE)

A Laravel Nova 5 field that groups multiple Nova fields and stores their values as a single JSON column. Supports nested wrappers, validation, `dependsOn` for dynamic fields, and works seamlessly on create, update, and detail views.

Requirements
------------

[](#requirements)

- PHP ^8.2
- Laravel Nova ^5.0
- Vue 3 (included with Nova 5)

Installation
------------

[](#installation)

```
composer require codehero-mx/nova-json-wrapper
```

The service provider is auto-registered.

Usage
-----

[](#usage)

### 1. Cast the JSON column on your model

[](#1-cast-the-json-column-on-your-model)

```
class User extends Model
{
    protected $casts = [
        'setting_value' => 'array',
    ];
}
```

### 2. Add `HasJsonWrapper` trait and define fields in your Nova resource

[](#2-add-hasjsonwrapper-trait-and-define-fields-in-your-nova-resource)

```
use CodeheroMx\JsonWrapper\JsonWrapper;
use CodeheroMx\JsonWrapper\HasJsonWrapper;
use Laravel\Nova\Fields\Number;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Http\Requests\NovaRequest;

class User extends Resource
{
    use HasJsonWrapper;

    public function fields(NovaRequest $request): array
    {
        return [
            Text::make('Name', 'name')->rules('required'),

            JsonWrapper::make('options', [
                Text::make('First Name', 'first_name')->rules('required'),
                Text::make('Last Name', 'last_name')->rules('required'),
                Number::make('Age', 'age')->rules('required', 'numeric', 'min:0'),
            ]),
        ];
    }
}
```

This stores the following JSON in the `options` column:

```
{ "first_name": "John", "last_name": "Doe", "age": 30 }
```

### 3. Nested wrappers

[](#3-nested-wrappers)

You can nest `JsonWrapper` fields to create deep JSON structures:

```
JsonWrapper::make('options', [
    Text::make('First Name', 'first_name')->rules('required'),
    Text::make('Last Name', 'last_name')->rules('required'),

    JsonWrapper::make('body_mass', [
        Number::make('Weight', 'weight')->rules('required'),
        Number::make('Height', 'height')->rules('required'),
    ]),
])
```

Result:

```
{
    "first_name": "John",
    "last_name": "Doe",
    "body_mass": {
        "weight": 70,
        "height": 180
    }
}
```

### 4. Dynamic fields with `dependsOn`

[](#4-dynamic-fields-with-dependson)

`JsonWrapper` supports Nova's `dependsOn` to dynamically change the child fields based on another field's value. This is useful when the JSON structure varies depending on a selection.

In the `dependsOn` callback you receive the `JsonWrapper` instance — replace its `$field->fields` collection with the new set of fields and call `$field->show()` or `$field->hide()` as needed.

```
use Laravel\Nova\Fields\FormData;
use Laravel\Nova\Fields\Number;
use Laravel\Nova\Fields\Select;
use Laravel\Nova\Fields\Text;

public function fields(NovaRequest $request): array
{
    return [
        Select::make('Role', 'role')
            ->options([
                'developer' => 'Developer',
                'designer' => 'Designer',
            ])
            ->rules('required'),

        JsonWrapper::make('profile', $this->profileFieldsFor($this->resource->role ?? ''))
            ->dependsOn(
                ['role'],
                function (JsonWrapper $field, NovaRequest $request, FormData $formData) {
                    $role = $formData->get('role');

                    $field->fields = collect(match ($role) {
                        'developer' => [
                            Select::make('Language', 'language')
                                ->options(['php' => 'PHP', 'js' => 'JavaScript', 'go' => 'Go'])
                                ->rules('required'),
                            Number::make('Years of Experience', 'experience')->rules('required', 'min:0'),
                        ],
                        'designer' => [
                            Text::make('Tool', 'tool')->rules('required'),
                            Text::make('Portfolio URL', 'portfolio_url')->rules('required', 'url'),
                        ],
                        default => [],
                    });

                    $role ? $field->show() : $field->hide();
                },
            ),
    ];
}

/**
 * Return the initial child fields for edit/detail views.
 */
private function profileFieldsFor(string $role): array
{
    return match ($role) {
        'developer' => [
            Select::make('Language', 'language')
                ->options(['php' => 'PHP', 'js' => 'JavaScript', 'go' => 'Go'])
                ->rules('required'),
            Number::make('Years of Experience', 'experience')->rules('required', 'min:0'),
        ],
        'designer' => [
            Text::make('Tool', 'tool')->rules('required'),
            Text::make('Portfolio URL', 'portfolio_url')->rules('required', 'url'),
        ],
        default => [],
    };
}
```

When the user selects a role, the wrapper swaps its child fields accordingly. On edit, existing JSON values are automatically resolved into the fields.

> **Tip:** The initial fields passed to `JsonWrapper::make()` are used when the resource already exists (edit/detail). The `dependsOn` callback fires on every form sync and replaces them dynamically.

### 5. Showing fields on the index view

[](#5-showing-fields-on-the-index-view)

By default, child fields are hidden on the index/list view. Use `indexFields()` to choose which ones to display:

```
JsonWrapper::make('options', [
    Text::make('First Name', 'first_name')->rules('required'),
    Text::make('Last Name', 'last_name')->rules('required'),
    Number::make('Age', 'age')->rules('required', 'numeric', 'min:0'),
])->indexFields(['first_name', 'age'])
```

Only `First Name` and `Age` will appear as columns on the resource index. The fields are resolved from the JSON column automatically.

> **Note:** Index fields are **read-only display columns**. Since the data lives inside a JSON column, they cannot be sorted, filtered, or searched through Nova's built-in mechanisms. They also only work with first-level child fields (not nested wrappers).

How it works
------------

[](#how-it-works)

- **`JsonWrapper`** extends `Laravel\Nova\Fields\Field` with the `SupportsDependentFields` trait. It manages a collection of child fields that are resolved, filled, and validated against the JSON column.
- **`HasJsonWrapper`** is a trait for your Nova Resource that ensures the wrapper is included during form operations (create, update, sync) and flattens child fields on the detail view so they display individually.
- On the **frontend**, the Vue 3 component uses Nova's `DependentFormField` mixin to handle `dependsOn` synchronization, visibility toggling, and delegating `fill()` to rendered child component instances.

Notes
-----

[](#notes)

- There are no visual indications that the fields are wrapped in JSON — they appear as normal Nova fields. This is intentional.
- The `HasJsonWrapper` trait is **required** on any resource that uses `JsonWrapper`. It handles field visibility across different Nova controllers (create, update, detail, index, sync).
- Validation rules on child fields work exactly like regular Nova fields (`->rules('required', 'numeric')`, etc.).

Credits
-------

[](#credits)

This package is based on [nova-json-wrapper](https://github.com/dcasia/nova-json-wrapper) by [Digital Creative](https://github.com/dcasia), originally licensed under MIT. It has been upgraded and adapted for Laravel Nova 5.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://raw.githubusercontent.com/codehero-mx/nova-json-wrapper/master/LICENSE) for more information.

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance82

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

96d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/35c1c6e446fbc2a96e779a2a073bc1127fe1410e833c7e52611f3450a7bec58b?d=identicon)[iBet7o](/maintainers/iBet7o)

---

Tags

jsonlaravelnovajson-wrapper

### Embed Badge

![Health badge](/badges/codehero-mx-nova-json-wrapper/health.svg)

```
[![Health](https://phpackages.com/badges/codehero-mx-nova-json-wrapper/health.svg)](https://phpackages.com/packages/codehero-mx-nova-json-wrapper)
```

###  Alternatives

[digital-creative/nova-json-wrapper

Allows you to group Nova fields and merge their output into a single JSON column.

1280.3k1](/packages/digital-creative-nova-json-wrapper)[stepanenko3/nova-json

Nova json field to spread a json column throughout multiple fields.

42269.5k](/packages/stepanenko3-nova-json)[interaction-design-foundation/nova-html-card

A Laravel Nova card to display arbitrary HTML content

67817.0k3](/packages/interaction-design-foundation-nova-html-card)[markwalet/nova-modal-response

A Laravel Nova asset for Modal responses on an action.

17818.7k](/packages/markwalet-nova-modal-response)[dniccum/nova-documentation

A Laravel Nova tool that allows you to add markdown-based documentation to your administrator's dashboard.

37118.9k](/packages/dniccum-nova-documentation)[json-mapper/laravel-package

The JsonMapper package for Laravel

25188.9k3](/packages/json-mapper-laravel-package)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
