PHPackages                             lookyman/json-mapper - 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. lookyman/json-mapper

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

lookyman/json-mapper
====================

Strict JSON to object hydrator based on PHPStan.

0.0.6(4y ago)19MITPHPPHP ^8.0

Since Dec 30Pushed 4y ago1 watchersCompare

[ Source](https://github.com/lookyman/json-mapper)[ Packagist](https://packagist.org/packages/lookyman/json-mapper)[ RSS](/packages/lookyman-json-mapper/feed)WikiDiscussions main Synced 4w ago

READMEChangelog (6)Dependencies (5)Versions (7)Used By (0)

JSON Mapper
===========

[](#json-mapper)

Strict JSON to object hydrator based on [PHPStan](https://phpstan.org/).

Usage
-----

[](#usage)

```
use Lookyman\JsonMapper\MapperBuilder
use PHPUnit\Framework\Assert;

class Foo
{
    public function __construct(public string $foo)
    {
    }
}

class Bar
{
    public function __construct(public Foo $first)
    {
    }
}

$result = (new MapperBuilder())
    ->build()
    ->map(Bar::class, '{"first":{"foo":"wtf"}}');

Assert::assertEquals(
    new Bar(new Foo('wtf')),
    $result,
);
```

If the parameter is not present in source, and has a scalar default value, it will be assigned that value. If the parameter is not present in source, but is nullable, it will be assigned a `NULL` value. If the source contains keys not present in parameter names, those will be ignored. Otherwise, we do not do any guessing or type casting.

In case of any error, `Lookyman\JsonMapper\Exception\MapperException` is thrown.

Supported types
---------------

[](#supported-types)

- Scalars (including literals and integer ranges),
- arrays (including associative and shapes),
- iterables,
- `class-string` (including generic),
- `object`,
- normal class objects (including generic),
- unions (including nullable parameters),
- backed enums.

See [PHPStan documentation](https://phpstan.org/writing-php-code/phpdoc-types) and `tests` directory for examples.

Caveats
-------

[](#caveats)

All classes must be instantiable with a public constructor. If your types contain interfaces or abstract classes, use `MapperBuilder::withClassMapping` to provide a map to concrete classes.

Questions?
----------

[](#questions)

This is a pet project I played with over the 2021 end of year holidays, because I saw [@Ocramius](https://twitter.com/Ocramius) looking for a similar library a few weeks earlier. At the moment, I have no ambitions with it, I just wanted to see if this approach is feasible.

It probably contains a lot of bugs.

If you have any questions, the answer is probably "I don't know". If you have any requests, I will probably not respond.

But I reserve the right to change my mind at any point.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

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

Total

6

Last Release

1587d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

jsonmapperphpstan

###  Code Quality

TestsPHPUnit

Type Coverage Yes

### Embed Badge

![Health badge](/badges/lookyman-json-mapper/health.svg)

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

###  Alternatives

[ticketswap/phpstan-error-formatter

A minimalistic error formatter for PHPStan

87578.8k35](/packages/ticketswap-phpstan-error-formatter)[slam/phpstan-extensions

Slam extension of phpstan

702.5M74](/packages/slam-phpstan-extensions)[ramsey/devtools

A Composer plugin to aid PHP library and application development.

7134.7k26](/packages/ramsey-devtools)[johnbillion/wp-compat

PHPStan extension to help verify that your PHP code is compatible with a given version of WordPress

24115.0k10](/packages/johnbillion-wp-compat)

PHPackages © 2026

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