PHPackages                             addequatte/json-serializer - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. addequatte/json-serializer

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

addequatte/json-serializer
==========================

Simply JsonSerializable interface realization to convert models to json

0.0.2-alpha(4y ago)02MITPHPPHP &gt;=8.0.0

Since Mar 18Pushed 4y ago1 watchersCompare

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

READMEChangelog (2)DependenciesVersions (3)Used By (0)

### Simply JsonSerializable interface realization to convert models to json

[](#simply-jsonserializable-interface-realization-to-convert-models-to-json)

Features
--------

[](#features)

- Convert children models to json.
- Hide fields you want.
- Process result field

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

[](#installation)

```
composer require addequatte/json-serializer
```

For example
-----------

[](#for-example)

```
/**
 * lib/Example/index.php
 */
namespace Addequatte\JsonSerializer\Example;

use Addequatte\JsonSerializer\Model\JsonSerializable;
use Addequatte\JsonSerializer\Processor\FieldProcessor;

require_once dirname(__DIR__) . '/../vendor/autoload.php';

class Author extends JsonSerializable
{
    private $id = 1;

    private $name = 'Author name';

    private $gender = 'male';

    private $birthDate;

    private $books;

    public function __construct()
    {
        $this->birthDate = new \DateTime('2000-01-12');

        $this->books[] = new Book();
    }

    /**
     * @return int
     */
    public function getId(): int
    {
        return $this->id;
    }

    /**
     * @return string
     */
    public function getName(): string
    {
        return $this->name;
    }

    /**
     * @return string
     */
    public function getGender(): string
    {
        return $this->gender;
    }

    /**
     * @return \DateTime
     */
    public function getBirthDate(): \DateTime
    {
        return $this->birthDate;
    }

    /**
     * @return array
     */
    public function getBooks(): array
    {
        return $this->books;
    }
}

class Book extends JsonSerializable
{
    private $id = 1;

    private $name = 'Book Name';

    private $description = 'Book description';

    /**
     * @return int
     */
    public function getId(): int
    {
        return $this->id;
    }

    /**
     * @return string
     */
    public function getName(): string
    {
        return $this->name;
    }

    /**
     * @return string
     */
    public function getDescription(): string
    {
        return $this->description;
    }
}

$author = new Author();

print_r(json_encode($author, JSON_PRETTY_PRINT) . PHP_EOL);

$processor = new FieldProcessor();

$processor->addClosure(Author::class,'birthDate', function ($value) {
    return $value->format('d.m.Y H:i:s');
});

$processor->addClosure(Book::class,'name', function ($value) {
    return 'Processed book name';
});

$jsonSerializeHandler = new \Addequatte\JsonSerializer\Handlers\JsonSerializeHandler($processor);

$jsonSerializeHandler->addHiddenFields(Author::class, ['gender']);
$jsonSerializeHandler->addHiddenFields(Book::class, ['description']);

print_r(json_encode($jsonSerializeHandler->jsonSerialize($author), JSON_PRETTY_PRINT));
```

Result for first case
---------------------

[](#result-for-first-case)

```
{
  "id": 1,
  "name": "Author name",
  "gender": "male",
  "birthDate": {
    "date": "2000-01-12 00:00:00.000000",
    "timezone_type": 3,
    "timezone": "Asia\/Krasnoyarsk"
  },
  "books": [
    {
      "id": 1,
      "name": "Book Name",
      "description": "Book description"
    }
  ]
}
```

Result for second case
----------------------

[](#result-for-second-case)

```
{
  "id": 1,
  "name": "Author name",
  "birthDate": "12.01.2000 00:00:00",
  "books": [
    {
      "id": 1,
      "name": "Processed book name"
    }
  ]
}
```

- you can get all properties your models having getter
- How you can see it is pretty simple to use, just extend your model using **Addequatte\\JsonSerializer\\Model\\JsonSerializable**.
- If you want to hide some fields you can use **setHiddenFields(array $hiddenFields): void** method
- You can hide fields from children model easily just using **$jsonSerializeHandler-&gt;addHiddenFields(Author::class, \['gender'\])**
- You can change model fields easily just using **$processor-&gt;addClosure(Author::class,'birthDate', function ($value) { return $value-&gt;format('d.m.Y H:i:s'); })**
- You can write your own processor implement **ProcessorInterface**

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

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

Total

2

Last Release

1519d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0164e8dc21e310162b1c3a401667a2a0b161eac35bf0fc36541e4d34027ab9a6?d=identicon)[addequatte](/maintainers/addequatte)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/addequatte-json-serializer/health.svg)

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

PHPackages © 2026

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