PHPackages                             sanmai/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. sanmai/json-serializer

ActiveLibrary

sanmai/json-serializer
======================

Flexible JSON Serializer

0.2.7(11mo ago)142.0k↓13%4MITPHPPHP &gt;=8.2CI passing

Since Sep 28Pushed 5mo ago1 watchersCompare

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

READMEChangelog (2)Dependencies (10)Versions (11)Used By (4)

Flexible JSON Serializer
========================

[](#flexible-json-serializer)

[![Latest Stable Version](https://camo.githubusercontent.com/20076afa149b298d606e8f72b29365f8eece719cb8aa21fc494c53d0827348db/68747470733a2f2f706f7365722e707567782e6f72672f73616e6d61692f6a736f6e2d73657269616c697a65722f762f737461626c65)](https://packagist.org/packages/sanmai/json-serializer)[![Coverage Status](https://camo.githubusercontent.com/fec015f90e488f7831f1a501787beb5331637368592755e0ab9609ba8dacda39/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f73616e6d61692f6a736f6e2d73657269616c697a65722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/sanmai/json-serializer?branch=master)

This library is a thin wrapper around [jms/serializer](https://github.com/schmittjoh/serializer).

```
composer require sanmai/json-serializer

```

The purpose of this library is to make simpler deserialization/serialization of objects and, specifically, of arrays of objects, and scalar values. All you need is to follow a simple protocol.

### ItemList

[](#itemlist)

JMS Serializer supports deserializing arrays out of the box, but it is ever so slightly complicated since a user must specify a type in a full form, as in `array`, all the while returned deserialized value will be a plain array. This library abstracts away this extra complexity by providing a two-method protocol instead.

For example, deserialising this object:

```
use JSONSerializer\Contracts\ItemList;

class ItemListExample implements ItemList
{
    /** @var ItemExample[] */
    public $items = [];

    public static function getListType(): string
    {
        return ItemExample::class;
    }

    public static function withList(array $list)
    {
        $itemList = new self();
        $itemList->items = $list;

        return $itemList;
    }
}
```

From a JSON array:

```
[
    {"name": "foo"},
    {"name": "bar"}
]
```

With an all-familiar method:

```
use JSONSerializer\Serializer;

$serializer = new Serializer();

$result = $serializer->deserialize($json, ItemListExample::class);
```

Will leave an instance of `ItemListExample` in `$result` with `$result->items` filled with two items as in the source array.

### ScalarValue

[](#scalarvalue)

There's a similar convenience interface called `ScalarValue` to aid with unserializing wrapped primitive scalar values.

```
use JSONSerializer\Contracts\ScalarValue;

class ScalarValueExample implements ScalarValue
{
    /** @var int */
    public $value;

    public static function withValue($value)
    {
        $item = new self();
        $item->value = $value;

        return $item;
    }

    public static function getType(): string
    {
        return 'int';
    }
}
```

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance63

Regular maintenance activity

Popularity29

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 86.8% 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 ~189 days

Recently: every ~402 days

Total

10

Last Release

355d ago

PHP version history (4 changes)0.1PHP ^7.3 || ^8.0

0.2.3PHP &gt;=7.3

0.2.5PHP &gt;=7.4

0.2.7PHP &gt;=8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/edcb8dde95c71b1c97c3c91e57d3548795fa2014c657744fb878e2be3b5949fc?d=identicon)[sanmai](/maintainers/sanmai)

---

Top Contributors

[![sanmai](https://avatars.githubusercontent.com/u/139488?v=4)](https://github.com/sanmai "sanmai (33 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (5 commits)")

---

Tags

jsonphpserializer

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[jms/serializer-bundle

Allows you to easily serialize, and deserialize data of any complexity

1.8k89.3M627](/packages/jms-serializer-bundle)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[horstoeko/zugferd

A library for creating and reading european electronic invoices

4174.3M18](/packages/horstoeko-zugferd)[goetas-webservices/xsd2php-runtime

Convert XSD (XML Schema) definitions into PHP classes

4910.9M36](/packages/goetas-webservices-xsd2php-runtime)[sulu/article-bundle

Bundle for managing localized content-rich entities like blog-posts in the Sulu content management system

66409.6k2](/packages/sulu-article-bundle)[webit/w-firma-api

wFirma.pl API

1820.2k](/packages/webit-w-firma-api)

PHPackages © 2026

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