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

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

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

Map JSON structures to PHP classes

2.25.1(1y ago)2181.2M↓35.6%29[7 issues](https://github.com/JsonMapper/JsonMapper/issues)[3 PRs](https://github.com/JsonMapper/JsonMapper/pulls)20MITPHPPHP ^7.4 || ^8.0CI failing

Since Mar 15Pushed 1mo ago6 watchersCompare

[ Source](https://github.com/JsonMapper/JsonMapper)[ Packagist](https://packagist.org/packages/json-mapper/json-mapper)[ Docs](https://jsonmapper.net)[ GitHub Sponsors](https://github.com/DannyvdSluijs)[ RSS](/packages/json-mapper-json-mapper/feed)WikiDiscussions develop Synced 1w ago

READMEChangelog (10)Dependencies (15)Versions (71)Used By (20)

  ![JsonMapper logo](https://camo.githubusercontent.com/92c07bc67e17a28dff56bb1bb24368d6e7deac4d451ea04f9142af7a1954bf89/68747470733a2f2f6a736f6e6d61707065722e6e65742f696d616765732f6a736f6e6d61707065722e706e67)---

JsonMapper is a PHP library that allows you to map a JSON response to your PHP objects that are either annotated using doc blocks or use typed properties. For more information see the project website:

[![GitHub](https://camo.githubusercontent.com/4d2c1254245b3433f28f245fedef349f48ad0dc030000c629585db15f6745ee2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f4a736f6e4d61707065722f4a736f6e4d6170706572)](https://choosealicense.com/licenses/mit/)[![Packagist Version](https://camo.githubusercontent.com/6e4c07729e8f02d3734529e665a75d7a4abb7f2bd58ac1c94b7fc4834b660490/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a736f6e2d6d61707065722f6a736f6e2d6d6170706572)](https://packagist.org/packages/json-mapper/json-mapper)[![Packagist Downloads](https://camo.githubusercontent.com/c07741f1e1cb0d1a8b40d7e9f7e76c9e9958b3fd75f00bf7a88631db97045d97/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6a736f6e2d6d61707065722f6a736f6e2d6d6170706572)](https://camo.githubusercontent.com/c07741f1e1cb0d1a8b40d7e9f7e76c9e9958b3fd75f00bf7a88631db97045d97/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6a736f6e2d6d61707065722f6a736f6e2d6d6170706572)[![PHP from Packagist](https://camo.githubusercontent.com/1014125a8a91e6096530f05d0e9d2c074f4ab100659ed356463f9b1e8d58a73f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6a736f6e2d6d61707065722f6a736f6e2d6d6170706572)](#)[![GitHub Actions Workflow Status](https://camo.githubusercontent.com/91763bd77999330ecf934344f307ab986d6882b4c7a5d331b6783ebb6f72cbe9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f4a736f6e4d61707065722f4a736f6e4d61707065722f6275696c642e79616d6c)](https://camo.githubusercontent.com/91763bd77999330ecf934344f307ab986d6882b4c7a5d331b6783ebb6f72cbe9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f4a736f6e4d61707065722f4a736f6e4d61707065722f6275696c642e79616d6c)[![Coverage Status](https://camo.githubusercontent.com/a64597df6d705319e0922f304dc1f03714478311efc0f21fecc405e0a4130a49/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f4a736f6e4d61707065722f4a736f6e4d61707065722f62616467652e7376673f6272616e63683d646576656c6f70)](https://coveralls.io/github/JsonMapper/JsonMapper?branch=develop)

Why use JsonMapper
==================

[](#why-use-jsonmapper)

Continuously mapping your JSON responses to your own objects becomes tedious and is error-prone. Not mentioning the tests that need to be written for said mapping.

JsonMapper has been built with the most common usages in mind. To allow for those edge cases which are not supported by default, it can easily be extended as its core has been designed using middleware.

JsonMapper supports the following features

- Case conversion
- Debugging
- DocBlock annotations
- Final callback
- Namespace resolving
- PHP 7.4 Types properties

Installing JsonMapper
=====================

[](#installing-jsonmapper)

The installation of JsonMapper can easily be done with [Composer](https://getcomposer.org)

```
$ composer require json-mapper/json-mapper
```

The example shown above assumes that `composer` is on your `$PATH`.

How to use JsonMapper
=====================

[](#how-to-use-jsonmapper)

Given the following class definition

```
namespace JsonMapper\Tests\Implementation;

class SimpleObject
{
    /** @var string */
    private $name;

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

    public function setName(string $name): void
    {
        $this->name = $name;
    }
}
```

Combined with the following JsonMapper code as part of your application

```
$mapper = (new \JsonMapper\JsonMapperFactory())->default();
$object = new \JsonMapper\Tests\Implementation\SimpleObject();

$mapper->mapObject(json_decode('{ "name": "John Doe" }'), $object);

var_dump($object);
```

The above example will output:

```
class JsonMapper\Tests\Implementation\SimpleObject#1 (1) {
  private $name =>
  string(8) "John Doe"
}

```

Customizing JsonMapper
======================

[](#customizing-jsonmapper)

Writing your own middleware has been made as easy as possible with an `AbstractMiddleware` that can be extended with the functionality you need for your project.

```
use JsonMapper;

$mapper = (new JsonMapper\JsonMapperFactory())->bestFit();
$mapper->push(new class extends JsonMapper\Middleware\AbstractMiddleware {
    public function handle(
        \stdClass $json,
        JsonMapper\Wrapper\ObjectWrapper $object,
        JsonMapper\ValueObjects\PropertyMap $map,
        JsonMapper\JsonMapperInterface $mapper
    ): void {
        /* Custom logic here */
    }
});
```

Contributing
============

[](#contributing)

Please refer to [CONTRIBUTING.md](https://github.com/JsonMapper/JsonMapper/blob/main/CONTRIBUTING.md) for information on how to contribute to JsonMapper.

List of Contributors
--------------------

[](#list-of-contributors)

Thanks to everyone who has contributed to JsonMapper! You can find a detailed list of people that contributed to JsonMapper on [GitHub](https://github.com/JsonMapper/JsonMapper/graphs/contributors).

Sponsoring
----------

[](#sponsoring)

[![JetBrains logo.](https://camo.githubusercontent.com/b5639e7738c6dfae9fe3f3e20175570b7376ce2577a772e09c25c2d4f14bf86e/68747470733a2f2f7265736f75726365732e6a6574627261696e732e636f6d2f73746f726167652f70726f64756374732f636f6d70616e792f6272616e642f6c6f676f732f6a6574627261696e732e737667)](https://jb.gg/OpenSource)

This project is sponsored by JetBrains providing a license for PhpStorm to continue building on JsonMapper.

License
=======

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/JsonMapper/JsonMapper/blob/main/LICENSE) for more information.

###  Health Score

63

—

FairBetter than 99% of packages

Maintenance71

Regular maintenance activity

Popularity58

Moderate usage in the ecosystem

Community35

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 96.2% 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 ~36 days

Recently: every ~28 days

Total

53

Last Release

379d ago

Major Versions

0.3.0 → 1.0.02020-04-23

1.4.2 → 2.0.02021-01-07

PHP version history (3 changes)0.0.1PHP ^7.2 || ^8.0

2.6.0PHP ^7.1 || ^8.0

2.25.0PHP ^7.4 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/631515718006cc76dcc92e7672b8d2b265888cb6b5268212081cab15de114e92?d=identicon)[danny.vandersluijs](/maintainers/danny.vandersluijs)

---

Top Contributors

[![DannyvdSluijs](https://avatars.githubusercontent.com/u/618940?v=4)](https://github.com/DannyvdSluijs "DannyvdSluijs (306 commits)")[![guillaumesmo](https://avatars.githubusercontent.com/u/1309544?v=4)](https://github.com/guillaumesmo "guillaumesmo (3 commits)")[![dahse89](https://avatars.githubusercontent.com/u/5771799?v=4)](https://github.com/dahse89 "dahse89 (1 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (1 commits)")[![lambstream](https://avatars.githubusercontent.com/u/7003344?v=4)](https://github.com/lambstream "lambstream (1 commits)")[![paresh27](https://avatars.githubusercontent.com/u/25386515?v=4)](https://github.com/paresh27 "paresh27 (1 commits)")[![tachigami](https://avatars.githubusercontent.com/u/4858247?v=4)](https://github.com/tachigami "tachigami (1 commits)")[![aagjalpankaj](https://avatars.githubusercontent.com/u/15609300?v=4)](https://github.com/aagjalpankaj "aagjalpankaj (1 commits)")[![tiso](https://avatars.githubusercontent.com/u/920949?v=4)](https://github.com/tiso "tiso (1 commits)")[![CReimer](https://avatars.githubusercontent.com/u/1853907?v=4)](https://github.com/CReimer "CReimer (1 commits)")

---

Tags

hacktoberfesthydrationjsonjsonmappermappermappingmiddlewarephpjsonmiddlewaremapperjsonmapper

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[tempest/framework

The PHP framework that gets out of your way.

2.2k31.1k11](/packages/tempest-framework)[oro/platform

Business Application Platform (BAP)

641140.7k103](/packages/oro-platform)[shopware/platform

The Shopware e-commerce core

3.4k1.5M3](/packages/shopware-platform)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.4M506](/packages/shopware-core)[typo3/cms

TYPO3 CMS is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.

1.2k1.9M122](/packages/typo3-cms)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.1k16.8k](/packages/prestashop-prestashop)

PHPackages © 2026

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