PHPackages                             jfadich/json-property - 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. jfadich/json-property

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

jfadich/json-property
=====================

Transform an object property into an enhanced array

0.1.2(6y ago)34441MITPHPPHP &gt;=5.5.9CI failing

Since Dec 5Pushed 6y ago1 watchersCompare

[ Source](https://github.com/jfadich/json-property)[ Packagist](https://packagist.org/packages/jfadich/json-property)[ RSS](/packages/jfadich-json-property/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (8)Dependencies (2)Versions (10)Used By (0)

[![Build Status](https://camo.githubusercontent.com/3a59cb242900e7eeccd2cbc95e57ed65e6921d0d18627055188418582a47f210/687474703a2f2f696d672e736869656c64732e696f2f7472617669732f6a6661646963682f6a736f6e2d70726f70657274792e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/jfadich/json-property)[![Latest Version](https://camo.githubusercontent.com/16628a31a505502b2a48f7c71070c79b200da26ea73d216536017060e361e5bb/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a6661646963682f6a736f6e2d70726f70657274792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jfadich/json-property)[![HHVM Status](https://camo.githubusercontent.com/49a8261c0e6b41fb55898d20413a3c5c7c99d8245cb0fd490a0e7d644466006b/687474703a2f2f6868766d2e683463632e64652f62616467652f6a6661646963682f6a736f6e2d70726f70657274792e7376673f7374796c653d666c61742d737175617265)](http://hhvm.h4cc.de/package/jfadich/json-property)

JsonProperty
============

[](#jsonproperty)

JsonProperty provides a simple interface for storing key/value pairs to a single column on a model. This is useful for storing meta data or anything without a standard structure. The data is automatically serialized to a JSON when saving.

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

[](#installation)

Use composer to install the package

> composer require jfadich/json-property

### Requirements

[](#requirements)

- PHP &gt;= 5.5.9

### Configuration

[](#configuration)

1. Add the `JsonPropertyTrait` trait to the model
2. Set the `jsonProperty` property. This is the name of the method that will be called to access the JsonProperty object. You can set this to an array to enable multiple properties on a single model.

```
    namespace App;

    use Jfadich\JsonProperty\JsonPropertyTrait;
    use Jfadich\JsonProperty\JsonPropertyInterface;

    class SampleModel implements JsonPropertyInterface
    {
        use JsonPropertyTrait;
        protected $jsonProperty = 'meta';
    }

```

Usage
-----

[](#usage)

Call a method on the model named after the values you set to `$jsonProperty` to access the data stored in the JSON string

```
$model = new SampleModel();

$model->meta()->set('key', 'value');
$value = $model->meta()->get('key'); // 'value'
$value = $model->meta('key'); // 'value'

```

### Available Methods

[](#available-methods)

`has($key)`

Checks if there is a value for the given key

```
if($model->meta()->has('keyName')) {
    // Do something
}

```

`get( $key, $default = null )`

Get a value, or default if it is not present in the array. You can use the dot notation to access nested arrays.

`set($key, $value)`

Set/Update the given key/value pair.

`merge( array $values, array $allowedKeys = [] )`

Merge the given array into the saved object. This will not add keys that don't exist in original object unless the key is included in the whitelist.

`push( $key, $value )`

If the value for the given $key is an array the value will be pushed to the array.

`forget($key)`

Remove element from array. This will automatically be persisted

`all()`

Get all the elements from the array

### Examples

[](#examples)

The property on the object will always be an up to date JSON string so you can use what ever persistance method you choose.

```
$model = new SampleModel();

// Use dot notation to access nested values
$model->meta()->set('book.title', 'Cracking the Coding Interview');
$model->meta()->set('book.author', 'Gayle Laakmann McDowell');

// $model->meta
// { "book":{"title": "Cracking the Coding Interview", "author": "Gayle Laakmann McDowell"} }
//
// $model->meta()->all()
// array:3 [
//   "book" => array:2 [
//     "title" => "Cracking the Coding Interview"
//     "author" => "Gayle Laakmann McDowell"
//   ]
// ]

```

### Customization

[](#customization)

The JsonProperty object keeps the property on the model up to date with the current JSON string. If you want to automatically persist the data on update feel free to override the `saveJsonString()` method on the model.

```
public function saveJsonString($property, $jsonString)
{
    parent::saveJsonString($property, $jsonString);

    $this->saveToSQL(); // Persist to the database or any other method
}

```

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community8

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 ~225 days

Recently: every ~394 days

Total

8

Last Release

2280d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7854040?v=4)[John](/maintainers/jfadich)[@jfadich](https://github.com/jfadich)

---

Top Contributors

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

---

Tags

json

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jfadich-json-property/health.svg)

```
[![Health](https://phpackages.com/badges/jfadich-json-property/health.svg)](https://phpackages.com/packages/jfadich-json-property)
```

###  Alternatives

[sbsaga/toon

🧠 TOON for Laravel — a compact, human-readable, and token-efficient data format for AI prompts &amp; LLM contexts. Perfect for ChatGPT, Gemini, Claude, Mistral, and OpenAI integrations (JSON ⇄ TOON).

6442.4k](/packages/sbsaga-toon)[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)
