PHPackages                             vanengers/php-json-object-library - 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. vanengers/php-json-object-library

ActiveLibrary

vanengers/php-json-object-library
=================================

Base class for api

v1.3.0(1y ago)047[1 issues](https://github.com/vanengers/php-json-object-library/issues)mitPHPPHP &gt;=7.0.0CI passing

Since Oct 16Pushed 1y ago1 watchersCompare

[ Source](https://github.com/vanengers/php-json-object-library)[ Packagist](https://packagist.org/packages/vanengers/php-json-object-library)[ RSS](/packages/vanengers-php-json-object-library/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)Dependencies (1)Versions (10)Used By (0)

php-json-object-library
=======================

[](#php-json-object-library)

Base object for api

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

[](#installation)

` composer require vanengers/php-json-object-library`

Usage
-----

[](#usage)

```
use Vanengers\PhpJsonObjectLibrary\PhpJsonObject;
class SamplePhpObject extends PhpJsonObject
{
    public string $property = 'value';
}

```

### Use array to create object

[](#use-array-to-create-object)

```
$object = new SamplePhpObject(['property' => 'new value']);

```

### Or pass Json directly

[](#or-pass-json-directly)

```
$object = new SamplePhpObject("{\"property\":\"new value\"}");

```

### Use setters

[](#use-setters)

```
class SamplePhpObject extends PhpJsonObject
{
    public string $property = 'value';

    public function setProperty(string $data): self
    {
        $this->property = $value;
        // do stuff here like parsing data, transformation or validations

        return $this;
    }
}

```

### Translate json/array data to another object property

[](#translate-jsonarray-data-to-another-object-property)

```
class SamplePhpObject extends PhpJsonObject
{
    public $mappers = [
           'property_other_remote_name' => 'property'
    ];

    public string $property = 'value';

    ...
}

```

```
$object = new SamplePhpObject("{\"property_other_remote_name\":\"new value\"}");
$object->getProperty(); // returns: "new value"

```

### serialize to json / create array

[](#serialize-to-json--create-array)

```
$object = new SamplePhpObject("{\"property\":\"new value\"}");
$array = $object->toArray();
$json = $object->toJson();

```

### skip certain fields in object from being serialized

[](#skip-certain-fields-in-object-from-being-serialized)

```
$object = new SamplePhpObject("{\"property\":\"new value\"}");
$array = $object->toArray(['skip' => ['property']]);
$json = $object->toJson(['skip' => ['property']]);

```

### skip certain fields in object from being serialized

[](#skip-certain-fields-in-object-from-being-serialized-1)

```
$object = new SamplePhpObject("{\"property\":\"new value\"}");
$array = $object->toArray(['skip' => ['property']]);
$json = $object->toJson(['skip' => ['property']]);

```

### skip certain fields in object from being serialized only when value is null

[](#skip-certain-fields-in-object-from-being-serialized-only-when-value-is-null)

```
$object = new SamplePhpObject("{\"property\":\"new value\"}");
$array = $object->toArray(['skip_null' => ['property']]);
$json = $object->toJson(['skip_null' => ['property']]);

```

### skip certain fields in object from being serialized only when value is empty()

[](#skip-certain-fields-in-object-from-being-serialized-only-when-value-is-empty)

```
$object = new SamplePhpObject("{\"property\":\"new value\"}");
$array = $object->toArray(['skip_empty' => ['property']]);
$json = $object->toJson(['skip_empty' => ['property']]);

```

### exclude properties from serialization

[](#exclude-properties-from-serialization)

```
class SamplePhpObject extends PhpJsonObject
{
    public $exclude_from_array = [
           'property'
    ];

    public string $property = 'value';
    public string $property2 = 'value';

    ...
}

```

Which results in

```
{
    "property2": "value"
}

```

### Add prefixes to your keys, when your resultset defines multidimensional arrays with some keys being the same

[](#add-prefixes-to-your-keys-when-your-resultset-defines-multidimensional-arrays-with-some-keys-being-the-same)

#### You can then process the parent key-name and add the whole key in the mappers

[](#you-can-then-process-the-parent-key-name-and-add-the-whole-key-in-the-mappers)

```
class SamplePhpObject extends PhpJsonObject
{
    public $mappers = [
           'person_name' => 'author',
           'recipient_name' => 'recipient',
    ];

    public string $author = '';
    public string $recipient = '';

    ...
}

```

#### While your resultset is like this

[](#while-your-resultset-is-like-this)

```
{
    "person": {
        "name": "John Doe"
    },
    "recipient": {
        "name": "Jane Doe"
    }
}

```

#### You should use the prefix option while parsing the json and use setters

[](#you-should-use-the-prefix-option-while-parsing-the-json-and-use-setters)

```
class SamplePhpObject extends PhpJsonObject
{
    public $mappers = [
           'person_name' => 'author',
           'recipient_name' => 'recipient',
    ];

    public string $author = '';
    public string $recipient = '';

    public function setPerson($data)
    {
        if (is_array($data)) {
            $this->fromArray($data);
        }
    }

    public function setRecipient($data)
    {
        if (is_array($data)) {
            $this->fromArray($data);
        }
    }
}

```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance42

Moderate activity, may be stable

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

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

Recently: every ~119 days

Total

9

Last Release

468d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/90f2324639ed35bd07704cf01a6c124478ec162147a7e60d0ca61cfd8f463a0a?d=identicon)[georgevanengers](/maintainers/georgevanengers)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/vanengers-php-json-object-library/health.svg)

```
[![Health](https://phpackages.com/badges/vanengers-php-json-object-library/health.svg)](https://phpackages.com/packages/vanengers-php-json-object-library)
```

PHPackages © 2026

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