PHPackages                             eluhr/yii2-json-attribute-behavior - 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. eluhr/yii2-json-attribute-behavior

ActiveYii2-extension[Parsing &amp; Serialization](/categories/parsing)

eluhr/yii2-json-attribute-behavior
==================================

This behavior automatically decodes attributes from JSON to arrays before validation, handling errors and re-encoding if validation fails.

1.0.0(2y ago)21.7kBSD-3-ClausePHP &gt;=7.4

Since Dec 28Compare

[ Source](https://github.com/eluhr/yii2-json-attribute-behavior)[ Packagist](https://packagist.org/packages/eluhr/yii2-json-attribute-behavior)[ RSS](/packages/eluhr-yii2-json-attribute-behavior/feed)WikiDiscussions Synced yesterday

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

Yii2 JSON Attribute Behavior
============================

[](#yii2-json-attribute-behavior)

This behavior automatically decodes attributes from JSON to arrays before validation, handling errors and re-encoding if validation fails. With this a "real" json string can be further processed.

[![CI Workflow](https://github.com/eluhr/yii2-json-attribute-behavior/actions/workflows/ci.yml/badge.svg)](https://github.com/eluhr/yii2-json-attribute-behavior/actions/workflows/ci.yml/badge.svg)

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

[](#installation)

The preferred way to install this extension is through [composer](https://getcomposer.org/download/).

Either run

```
composer require --prefer-dist eluhr/yii2-json-attribute-behavior "*"

```

or add

```
"eluhr/yii2-json-attribute-behavior": "*"

```

to the `require` section of your `composer.json` file.

Usage
-----

[](#usage)

In a `yii\base\Model` or a derivation thereof, the behavior can be used as follows:

```
public function behaviors(): array
{
    $behaviors = parent::behaviors();
    $behaviors['json-attribute'] = [
        'class' => eluhr\jsonAttributeBehavior\JsonAttributeBehavior::class,
        'attributes' => [
            'data_json'
        ]
    ];
    return $behaviors;
}
```

By using this behavior it does not matter if the attribute is a string or an array. The behavior will always ensure, that the attribute is an array before saving the data to the database and yii will handle the rest.

This behavior supports [i18n](https://www.yiiframework.com/doc/guide/2.0/en/tutorial-i18n). By adding the `json-attribute-behavior` category in your config you can overwrite the default error messages.

Testing
-------

[](#testing)

After installing dependencies via composer you can run the tests with:

```
make test
```

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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

Unknown

Total

1

Last Release

919d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/07b2ebef20cf3f8b95894ff50fdb0ba46cf04c8d74ffbb6a4e724af8569a8aec?d=identicon)[eluhr](/maintainers/eluhr)

---

Top Contributors

[![eluhr](https://avatars.githubusercontent.com/u/13000805?v=4)](https://github.com/eluhr "eluhr (22 commits)")

---

Tags

jsonyii2extensionBehavior

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/eluhr-yii2-json-attribute-behavior/health.svg)

```
[![Health](https://phpackages.com/badges/eluhr-yii2-json-attribute-behavior/health.svg)](https://phpackages.com/packages/eluhr-yii2-json-attribute-behavior)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)[kdn/yii2-json-editor

JSON editor widget (josdejong/jsoneditor) for Yii 2.

23614.3k3](/packages/kdn-yii2-json-editor)[skeeks/cms

SkeekS CMS — control panel and tools based on php framework Yii2

13825.8k59](/packages/skeeks-cms)[dmstr/yii2-json-editor

Yii2 wrapper for "json-editor/json-editor" (is a fork of "jdorn/json-editor")

1064.7k6](/packages/dmstr-yii2-json-editor)[nizsheanez/yii2-json-rpc

A lightweight JsonRpc Server and Client for PHP

1834.3k](/packages/nizsheanez-yii2-json-rpc)

PHPackages © 2026

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