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

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

locustv2/yii2-json-data-behavior
================================

Enables you to easily encode and decode json in your activerecords.

1.0.0(9y ago)1240BSD-3-ClausePHP

Since Mar 31Pushed 9y agoCompare

[ Source](https://github.com/Locustv2/yii2-json-data-behavior)[ Packagist](https://packagist.org/packages/locustv2/yii2-json-data-behavior)[ Docs](https://github.com/locustv2/)[ RSS](/packages/locustv2-yii2-json-data-behavior/feed)WikiDiscussions master Synced 2mo ago

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

JsonData behavior for Yii2 ActiveRecords
========================================

[](#jsondata-behavior-for-yii2-activerecords)

Enables you to easily encode and decode json in your activerecords. It automatically encodes before validating and saving to database and decodes after.

[![Latest Stable Version](https://camo.githubusercontent.com/e73328250ef2b9cfc4c0db2034d614a80ad2fe2de68b60cdac893da500df4e79/68747470733a2f2f706f7365722e707567782e6f72672f4c6f6375737476322f796969322d6a736f6e2d646174612d6265686176696f722f762f737461626c65)](https://packagist.org/packages/Locustv2/yii2-json-data-behavior)[![Total Downloads](https://camo.githubusercontent.com/e1d9a7cc8364e841af23a959520a489c772cde6c11ecae32b401b80f8b99b40c/68747470733a2f2f706f7365722e707567782e6f72672f4c6f6375737476322f796969322d6a736f6e2d646174612d6265686176696f722f646f776e6c6f616473)](https://packagist.org/packages/Locustv2/yii2-json-data-behavior)[![Latest Unstable Version](https://camo.githubusercontent.com/c92bb413e9d34990d20da1ec8fe6aa3a33cd0f184b653d6e638cf0d35f3c61ab/68747470733a2f2f706f7365722e707567782e6f72672f4c6f6375737476322f796969322d6a736f6e2d646174612d6265686176696f722f762f756e737461626c65)](https://packagist.org/packages/Locustv2/yii2-json-data-behavior)[![License](https://camo.githubusercontent.com/b3f0543aa4f988fc6831edad83f25de537be7984cc6f43a957fae90cd1cde8f6/68747470733a2f2f706f7365722e707567782e6f72672f4c6f6375737476322f796969322d6a736f6e2d646174612d6265686176696f722f6c6963656e7365)](https://packagist.org/packages/Locustv2/yii2-json-data-behavior)

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

[](#installation)

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

Either run

```
php composer.phar require --prefer-dist locustv2/yii2-json-data-behavior

```

or add

```
{
    "require": {
        "locustv2/yii2-json-data-behavior": "~1.0.0"
    }
}
```

to your `composer.json` file.

Usage
-----

[](#usage)

```
public function behaviors()
{
    return [
        'class' => \locustv2\behaviors\JsonDataBehavior::className(),
        'dataAttribute' => 'hotel_data',
    ];
}
```

After configuring your activerecord as above, you can use as follows:

```
$model = Hotel::find()->one();

var_dump($model->getData('rooms')); // assume it returns a list of rooms
var_dump($model->getData('rooms.0.price')); // to get rooms data

$model->setData('ratings', [
    '5star' => ['count' => 100],
    '4star' => ['count' => 200],
    '3star' => ['count' => 20],
    '2star' => ['count' => 75],
    '1star' => ['count' => 50],
]);

var_dump($model->getData('ratings.3star.count')); // returns 20
```

To do
-----

[](#to-do)

- Add unit tests

Contributing
------------

[](#contributing)

Feel free to send pull requests.

License
-------

[](#license)

For license information check the [LICENSE](LICENSE.md)-file.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity63

Established project with proven stability

 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

3334d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/43f3d13b7b517fc44662d62165016bfeacf0a5858a1cdc7f5c3a8423042bc40b?d=identicon)[Locustv2](/maintainers/Locustv2)

---

Top Contributors

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

---

Tags

jsondataencodedecodeyii2Behavioractiverecord

### Embed Badge

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

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

###  Alternatives

[kherge/json

Encodes, decodes, and validates JSON data.

61226.6k6](/packages/kherge-json)

PHPackages © 2026

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