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

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

lendable/json-serializer
========================

JSON serializer/deserializer with an OOP interface

1.1.0(1mo ago)2117.3k↓15.4%[1 issues](https://github.com/Lendable/json-serializer/issues)[2 PRs](https://github.com/Lendable/json-serializer/pulls)MITPHPPHP &gt;=8.3,&lt;9CI passing

Since Nov 27Pushed 6d ago28 watchersCompare

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

READMEChangelog (9)Dependencies (18)Versions (21)Used By (0)

Lendable JSON Serializer
========================

[](#lendable-json-serializer)

[![Latest Stable Version](https://camo.githubusercontent.com/d96dd8b7aa034b24dfef6583ff27b64b7c6c71991aa6dc98076fad90444354e1/68747470733a2f2f706f7365722e707567782e6f72672f6c656e6461626c652f6a736f6e2d73657269616c697a65722f762f737461626c65)](https://packagist.org/packages/lendable/json-serializer)[![License](https://camo.githubusercontent.com/f851ed133ff715d47f718508b422d7dfac2b5cbeb8eafcb8d1600905a7a72347/68747470733a2f2f706f7365722e707567782e6f72672f6c656e6461626c652f6a736f6e2d73657269616c697a65722f6c6963656e7365)](https://packagist.org/packages/lendable/json-serializer)

Provides an opinionated object oriented interface for handling JSON serialization and deserialization in PHP.

Features
--------

[](#features)

- Throws exceptions on serialization and deserialization failure.
- Sane default serialization flags.

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

[](#installation)

```
composer require lendable/json-serializer
```

Why? Opinionated?
-----------------

[](#why-opinionated)

This library aids to simplify our most common usage patterns of JSON at Lendable by providing a strict and limited API, and not a generic solution.

### Type safety

[](#type-safety)

We follow the pattern of converting object graph(s) to data array(s) and then to JSON, this library fits into the `data array(s)  json` part of that flow. Due to this, it is restrictive in what can be serialized and deserialized as for our use case, these are error conditions. Data is deserialized always as a numeric (array root element) or an associative array (object root element). Therefore, this library may *not* fit your use case.

### Error handling

[](#error-handling)

The default `json_encode()` and `json_decode()` global functions from `ext-json` are still used, but delegated to in a safe manner. The potential error reporting from these functions can be:

- A `false` return value - except `json_decode('false')` also returns false, and isn't an error.
- Retrieved as code or message via `json_last_error()` or `json_last_error_msg()` - requires being checked every time.
- An exception via the `JSON_THROW_ON_ERROR` option in PHP 7.3 - requires opt-in to the functionality.

This library will always throw exceptions on serialization and deserialization failures, simplifying calling logic.

API
---

[](#api)

### Serialization `Serializer::serialize(array $data): string`

[](#serialization-serializerserializearray-data-string)

Serializes a data array into a JSON string.

Throws `SerializationFailed` on failure to serialize.

### Deserialization `Serializer::deserialize(string $json): array`

[](#deserialization-serializerdeserializestring-json-array)

Deserializes a JSON string into an `array`.

Throws `DeserializationFailed` on failure to deserialize. Throws `InvalidDeserializedData` if the data type of the resulting deserialized data is not an `array`.

###  Health Score

60

—

FairBetter than 98% of packages

Maintenance85

Actively maintained with recent releases

Popularity34

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity85

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 59.6% 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 ~337 days

Recently: every ~307 days

Total

9

Last Release

52d ago

Major Versions

0.1.1 → 1.0.02019-03-01

PHP version history (8 changes)0.1.0PHP &gt;=7.1

1.0.0PHP &gt;=7.2

1.0.1PHP &gt;=7.4.0,&lt;8.2.0

1.0.2PHP &gt;=8.0,&lt;8.2

1.0.3PHP &gt;=8.0,&lt;8.3

1.0.4PHP &gt;=8.1,&lt;9

1.0.5PHP &gt;=8.2,&lt;9

1.1.0PHP &gt;=8.3,&lt;9

### Community

Maintainers

![](https://www.gravatar.com/avatar/893f1dc6753940f80d1fe2e9a90db68961bb7f16eab85d6a868e7aecccf8de13?d=identicon)[ben-challis](/maintainers/ben-challis)

---

Top Contributors

[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (382 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (196 commits)")[![ben-challis](https://avatars.githubusercontent.com/u/8275163?v=4)](https://github.com/ben-challis "ben-challis (32 commits)")[![marmichalski](https://avatars.githubusercontent.com/u/57528542?v=4)](https://github.com/marmichalski "marmichalski (16 commits)")[![kunicmarko20](https://avatars.githubusercontent.com/u/13528674?v=4)](https://github.com/kunicmarko20 "kunicmarko20 (7 commits)")[![martin-georgiev](https://avatars.githubusercontent.com/u/4849482?v=4)](https://github.com/martin-georgiev "martin-georgiev (6 commits)")[![lendabot[bot]](https://avatars.githubusercontent.com/u/10513749?v=4)](https://github.com/lendabot[bot] "lendabot[bot] (1 commits)")[![AlexisColes](https://avatars.githubusercontent.com/u/8488871?v=4)](https://github.com/AlexisColes "AlexisColes (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[mck89/peast

Peast is PHP library that generates AST for JavaScript code

19037.7M41](/packages/mck89-peast)[karriere/json-decoder

JsonDecoder implementation that allows you to convert your JSON data into PHP class objects

141439.4k12](/packages/karriere-json-decoder)[sauladam/shipment-tracker

Parses tracking information for several carriers, like UPS, USPS, DHL and GLS by simply scraping the data. No need for any kind of API access.

9642.0k](/packages/sauladam-shipment-tracker)[jstewmc/rtf

Read and write Rich Text Format (RTF) documents with PHP

45143.1k6](/packages/jstewmc-rtf)[json-mapper/laravel-package

The JsonMapper package for Laravel

25188.9k3](/packages/json-mapper-laravel-package)[jamesmoss/toml

A parser for TOML implemented in PHP.

3231.7k15](/packages/jamesmoss-toml)

PHPackages © 2026

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