PHPackages                             xenolope/cartographer - 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. xenolope/cartographer

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

xenolope/cartographer
=====================

A super-simple library to map JSON documents to objects, similar to Java's Jackson

v0.6.1(11y ago)2167MITPHPPHP &gt;=5.4

Since Dec 20Pushed 11y ago3 watchersCompare

[ Source](https://github.com/jonjomckay/cartographer)[ Packagist](https://packagist.org/packages/xenolope/cartographer)[ RSS](/packages/xenolope-cartographer/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (4)Dependencies (2)Versions (6)Used By (0)

Cartographer
============

[](#cartographer)

[![Build Status](https://camo.githubusercontent.com/44de70b72c26eece234e6f407c499542493bc61e48e81b6a8a44e2f22da7c59b/68747470733a2f2f7472617669732d63692e6f72672f6a6f6e6a6f6d636b61792f636172746f677261706865722e737667)](https://travis-ci.org/jonjomckay/cartographer)

Cartographer is a super-simple library for deserializing JSON into POPOs, similar to [FasterXML's `jackson-databind` package](https://github.com/FasterXML/jackson-databind) for Java.

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

[](#installation)

The library can be installed with Composer, by including the following in your `composer.json`:

```
{
    "require": {
        "xenolope/cartographer": "~0.5"
    }
}
```

Usage
-----

[](#usage)

### POPOs

[](#popos)

Your POPOs must have a property and corresponding setter, with either the property having a `@var ClassName` docblock, or the setter having a type hint.

Setters are called directly, and properties are never touched, even if they're declared `public` (though this might be added in a later version).

Simple values are converted to the types given in their `@var` docblocks (using `settype()`), objects are created based on the class specified in the `@var` docblocks, and arrays of objects are also created, and can be specified with the `@var ClassName[]` notation.

```
class Contact
{

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

    /**
     * @var Address
     */
    private $address;

    /**
     * Note, this property doesn't have a @var docblock, but the corresponding setter
     * below *does* have a type hint
     */
    private $secondaryAddress;

    /**
     * @var Note[]
     */
    private $notes;

    /**
     * @param string $name
     */
    public function setName($name)
    {
        $this->name = $name;
    }

    /**
     * @param Address $address
     */
    public function setAddress($address)
    {
        $this->address = $address;
    }

    /**
     * @param Address $secondaryAddress
     */
    public function setAddress(Address $secondaryAddress)
    {
        $this->secondaryAddress = $secondaryAddress;
    }

    /**
     * @param Note[] $notes
     */
    public function setNotes($notes)
    {
        $this->notes = $notes;
    }
}
```

### Mapping

[](#mapping)

```
// Create a new instance of the Mapper
$mapper = new \Xenolope\Cartographer\Mapper();

// Map a JSON string to a POPO

// PHP 5.4
$object = $mapper->mapString(
    '{"name":"Liz Lemon","address":{"street":"168 Riverside Dr.","city":"New York"}}',
    'Vendor\Package\Entity\Contact'
);

// PHP >=5.5
$object = $mapper->mapString(
    '{"name":"Liz Lemon","address":{"street":"168 Riverside Dr.","city":"New York"}}',
    Contact::class
);

// Map an already decoded (to array) JSON document to a POPO

// This might happen automatically in your Request class, for example
$jsonDocument = json_decode(
    '{"name":"Liz Lemon","address":{"street":"168 Riverside Dr.","city":"New York"}}',
    true
);

// PHP 5.4
$object = $mapper->map($jsonDocument, 'Vendor\Package\Entity\Contact');

// PHP >= 5.5
$object = $mapper->map(
    '{"name":"Liz Lemon","address":{"street":"168 Riverside Dr.","city":"New York"}}',
    Contact::class
);
```

Roadmap
-------

[](#roadmap)

- Add custom property mapping, for when JSON properties don't match with POPO properties
- Maybe add in support for serializing a POPO to JSON

Thanks
------

[](#thanks)

This library was inspired by:

- [`fasterxml/jackson-databind`](https://github.com/FasterXML/jackson-databind) for Java
- [`netresearch/jsonmapper`](https://github.com/netresearch/jsonmapper) for PHP

License
-------

[](#license)

Cartographer is released under the MIT License; please see [LICENSE](LICENSE) for more information.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity52

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

Total

4

Last Release

4119d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6749b31cc9bc30bf922a93dfae8bb3132bc2e2051be3bc7c9e5ac0b91fe0bfd3?d=identicon)[jonjomckay](/maintainers/jonjomckay)

---

Top Contributors

[![jonjomckay](https://avatars.githubusercontent.com/u/456645?v=4)](https://github.com/jonjomckay "jonjomckay (14 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/xenolope-cartographer/health.svg)

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

###  Alternatives

[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k472.8M135](/packages/mtdowling-jmespathphp)[opis/closure

A library that can be used to serialize closures (anonymous functions) and arbitrary data.

2.6k230.0M283](/packages/opis-closure)[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M226](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M63](/packages/sabberworm-php-css-parser)[michelf/php-markdown

PHP Markdown

3.5k52.4M344](/packages/michelf-php-markdown)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)

PHPackages © 2026

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