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

ActiveLibrary

supplyhog/yii2-json-object-behavior
===================================

48.4k2PHP

Since Feb 26Pushed 10y ago2 watchersCompare

[ Source](https://github.com/supplyhog/yii2-json-object-behavior)[ Packagist](https://packagist.org/packages/supplyhog/yii2-json-object-behavior)[ RSS](/packages/supplyhog-yii2-json-object-behavior/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

\#yii2-json-object-behavior

\##Installation Install this extension via [composer](http://getcomposer.org/download). Add this line to your project’s composer.json

```
supplyhog/yii2-json-object-behavior” : “dev-master”
```

\##What Does It Do?

JSON string field in the database becomes usable object or array of objects on an `yii\db\ActiveRecord`. No need to covert it back to a string for the database on saving. Just use it like a property.

\##Behavior Config

```
public function behaviors()
{
  return [
    //It is best to name your behaviors so that you can use more than one
    'field_behavior' => [
      'class' => 'supplyhog\JsonObjectBehavior\JsonObjectBehavior',
      'attribute' => 'field', //Name of the attribute that holds the JSON string
      'objectClass' => JsonObjectModel::className(), //Replace with your own class that extends JsonObjectModel
      'init' => true, // (new Model())->field will be an object
      // 'default' => [], // If you need defaults
    ],
    'field_array_behavior' => [
      'class' => 'supplyhog\JsonObjectBehavior\JsonObjectBehavior',
      'attribute' => 'fieldArray', //Name of the attribute that holds the JSON string
      'array' => true, //This is an array of objects
      'init' => true, // (new Model())->fieldArray will be an array
      'default' => [ //Object defaults. Useful sometimes. The field value
        'class' => JsonObjectModel::className(),  //Replace with your own class that extends JsonObjectModel
        'hello' => 'world', // the attribute hello will be set to "world" if the JSON string does not have a value for it
      ],
    ],
  ];
  }
```

\##JsonObjectModel

This is provided for a base for your JSON strings to change into. It extends `\yii\base\Model` which is quite helpful. It is not required, but if you use your own make sure you look at the magic `__toString()` in the JsonObjectModel and copy it over to yours.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity41

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.

### Community

### Embed Badge

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

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

PHPackages © 2026

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