PHPackages                             open-serializer/open-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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. open-serializer/open-serializer

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

open-serializer/open-serializer
===============================

Simple JSON serializer/deserializer.

0.1.0(5y ago)44.8k↑144.4%[1 PRs](https://github.com/open-serializer/open-serializer/pulls)MITPHPPHP ^7.4 || ^8.0

Since Jan 25Pushed 5y ago2 watchersCompare

[ Source](https://github.com/open-serializer/open-serializer)[ Packagist](https://packagist.org/packages/open-serializer/open-serializer)[ RSS](/packages/open-serializer-open-serializer/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (1)Dependencies (6)Versions (3)Used By (0)

Open Serializer
===============

[](#open-serializer)

[![codecov](https://camo.githubusercontent.com/64d3921d986bd9a282f2f5e3569444ad792725b6a428481cd353fbc0a8751aa6/68747470733a2f2f636f6465636f762e696f2f67682f6f70656e2d73657269616c697a65722f6f70656e2d73657269616c697a65722f6272616e63682f6d61696e2f67726170682f62616467652e7376673f746f6b656e3d44424c37524742474657)](https://codecov.io/gh/open-serializer/open-serializer)

Open Serializer is an uncomplicated library that recursively converts objects to and from JSON structure.

It is based on the brilliant idea of Matthias Noback described in the blog post [Designing a JSON serializer](https://matthiasnoback.nl/2017/07/designing-a-json-serializer/) and implemented in [matthiasnoback/naive-serializer](https://github.com/matthiasnoback/naive-serializer).

The core concepts of Open Serializer are:

- Stay as simple and small as possible.
- Do not require any supporting code or configuration other than object property types or `@var` annotations.
- Accept decoded or encoded JSON structures.
- Be open for extension.

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

[](#installation)

Open Serializer works on PHP 7.4/8.0 and is available on Packagist as `open-serializer/open-serializer`. To install it execute:

```
composer require open-serializer/open-serializer
```

Usage
-----

[](#usage)

### Supported types

[](#supported-types)

```
class Example {
    private string $typedProperty;

    /** @var string */
    private $docblockProperty;

    private ?self $selfTypedProperty;

    /** @var Example[] */
    private array $genericList;

    /** @var array */
    private array $genericArray;

    /** @var array */
    private array $genericArrayWithIntKey;

    /** @var array */
    private array $genericArrayWithStringKeys;

    /** @var array */
    private array $genericArrayOfArrays;
}
```

### Serialize to JsonObject

[](#serialize-to-jsonobject)

```
class Example {
    private ExampleText $text;
}
class ExampleText {
    private string $value;
}

$object = new Example(new ExampleText('example'));
$serializer = new JsonSerializer();
$toJson = $serializer->serialize($object)->encode(); // '{"text": {"value":"example"}}'
$toArray = $serializer->serialize($object)->decode(); // ['text' => ['value' => 'example']]
```

### Deserialize from JsonObject

[](#deserialize-from-jsonobject)

```
$jsonObject = JsonObject::fromJsonString('{"text": {"value":"example"}}');
// or
$jsonObject = JsonObject::fromArray(['text' => ['value' => 'example']]);

$serializer = new JsonSerializer();
$exampleObject = $serializer->deserialize(Example::class, $jsonObject);
```

### Unsupported types

[](#unsupported-types)

#### Types that has no valid case for JSON (de)serialization

[](#types-that-has-no-valid-case-for-json-deserialization)

- `resource`
- `callable`
- `Closure`
- `Generator`
- ...

#### Internal PHP objects and interfaces (at least by default, see [Extending](#Extending))

[](#internal-php-objects-and-interfaces-at-least-by-default-see-extending)

- `DateTime`
- `DateTimeImmutable`
- ...

#### Union types (PHP 8)

[](#union-types-php-8)

Union type will be treated as `mixed` and will be deserialized as is in JSON structure.

#### Constructor property (PHP 8)

[](#constructor-property-php-8)

Currently, constructor property promotion is not supported, planned for the future.

Extending
---------

[](#extending)

Sometimes there is a requirement to support internal types, interfaces or implement custom serialization logic. It can be done by implementing custom `TypeSerializer` and/or `TypeDeserializer`.

```
class Foo {}

/**
 * @implements TypeSerializer
 * @implements TypeDeserializer
 */
final class ExampleFooSerializer implements TypeSerializer, TypeDeserializer
{
    /**
     * @param Foo $object
     */
    public function serializeObject(object $object): array
    {
        // ...serialize Foo to array
    }

    public function deserializeObject(string $class, array $struct): Foo
    {
        // ...deserialize Foo from array
    }
}

$fooSerializer = new ExampleFooSerializer();
$jsonSerializer = new JsonSerializer(
    new StructSerializer([Foo::class => $fooSerializer]),
    new StructDeserializer([Foo::class => $fooSerializer])
);
```

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 76.5% 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

Unknown

Total

1

Last Release

1976d ago

### Community

Maintainers

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

![](https://avatars.githubusercontent.com/u/3485209?v=4)[Bronisław Białek](/maintainers/bronek89)[@bronek89](https://github.com/bronek89)

---

Top Contributors

[![dazet](https://avatars.githubusercontent.com/u/9936733?v=4)](https://github.com/dazet "dazet (13 commits)")[![bronek89](https://avatars.githubusercontent.com/u/3485209?v=4)](https://github.com/bronek89 "bronek89 (4 commits)")

---

Tags

deserializerphpserializer

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[driftingly/rector-laravel

Rector upgrades rules for Laravel Framework

1.2k14.2M667](/packages/driftingly-rector-laravel)[craftcms/cms

Craft CMS

3.6k3.6M2.9k](/packages/craftcms-cms)[symfony/serializer-pack

A pack for the Symfony serializer

1.1k28.9M247](/packages/symfony-serializer-pack)[veewee/xml

XML without worries

1836.6M38](/packages/veewee-xml)[phpdocumentor/reflection

Reflection library to do Static Analysis for PHP Projects

12524.8M137](/packages/phpdocumentor-reflection)[phparkitect/phparkitect

Enforce architectural constraints in your PHP applications

9184.1M24](/packages/phparkitect-phparkitect)

PHPackages © 2026

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