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

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

vergelijkgroep/yii2-json-behavior
=================================

Yii2 json encoding and decoding attribute behavior

v1.0.1(6y ago)0973MITPHPPHP &gt;=5.2.0

Since Oct 11Pushed 6y ago2 watchersCompare

[ Source](https://github.com/vergelijkgroep/yii2-json-behavior)[ Packagist](https://packagist.org/packages/vergelijkgroep/yii2-json-behavior)[ RSS](/packages/vergelijkgroep-yii2-json-behavior/feed)WikiDiscussions master Synced 3d ago

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

Yii2 JSON attribute behavior
============================

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

Automatically encode/decode attribute values in JSON via Yii2 Behavior.

Install
-------

[](#install)

Install via Composer:

```
composer require vergelijkgroep/yii2-json-behavior
```

or add

```
"vergelijkgroep/yii2-json-behavior" : "*"
```

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

Usage
-----

[](#usage)

### JsonBehavior

[](#jsonbehavior)

Configure your model:

```
use vergelijkgroep\JsonBehavior\JsonBehavior;

class Item extends \yii\db\ActiveRecord
{
    public function behaviors() {
        return [
            [
                'class' => JsonBehavior::class,
                'attributes' => ['attribute1', 'attribute2'],
                'emptyValue' => 'empty_value', // optional
                'asArray' => true,  // optional
            ]
        ];
    }
}
```

The attributes will now automatically be encoded and decoded:

```
$item = Item::findOne(1);
$item->attribute1['foo'] = 'bar';
$item->attribute2 = null;
$item->save(); // attribute1 will be encoded and saved as json

$item = Item::findOne(1);
echo $item->attribute1['foo']; // 'bar'
echo $item->attribute2; // 'empty_value'
```

#### emptyValue

[](#emptyvalue)

The `emptyValue` is the value of the attribute when its `null` after decoding from JSON. Default is `null`.

#### asArray

[](#asarray)

The `asArray` option defines the JSON decoding format, true for associative `array`, false for `object`. Default is false.

License
-------

[](#license)

[![MIT](https://camo.githubusercontent.com/52e652d5a838f7c24a397efbd29d850dee9c783291aa347d0f48438aab01a53f/68747470733a2f2f696d672e736869656c64732e696f2f636f636f61706f64732f6c2f41464e6574776f726b696e672e7376673f7374796c653d7374796c65266c6162656c3d4c6963656e7365266d61784167653d32353932303030)](LICENSE)

This software is distributed under the MIT license.

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity54

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

Every ~56 days

Total

2

Last Release

2399d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/fd7a17d6d76f3ded0d4e8903f506c325bf44da3e34e91ac99550365271e24804?d=identicon)[geertw](/maintainers/geertw)

![](https://www.gravatar.com/avatar/c49583aabecf7cf47d70d9764452177e0e7be2be8fe66be9be5f5470e67408e1?d=identicon)[HugovandeVliert](/maintainers/HugovandeVliert)

![](https://www.gravatar.com/avatar/4b0e6343766920d6fab746cb5330b7d267f77ced2609f89adcb847d9015a4ebf?d=identicon)[jangoessens](/maintainers/jangoessens)

---

Top Contributors

[![hugovandevliert](https://avatars.githubusercontent.com/u/25246106?v=4)](https://github.com/hugovandevliert "hugovandevliert (1 commits)")

---

Tags

phpyii2yii2-extensionjsonyii2Behavior

### Embed Badge

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

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

###  Alternatives

[craftcms/cms

Craft CMS

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

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

23614.3k3](/packages/kdn-yii2-json-editor)[devgroup/yii2-jsoneditor

Yii2 jsoneditor widget

11100.3k1](/packages/devgroup-yii2-jsoneditor)[nizsheanez/yii2-json-rpc

A lightweight JsonRpc Server and Client for PHP

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

PHPackages © 2026

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