PHPackages                             php-alchemist/json - 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. php-alchemist/json

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

php-alchemist/json
==================

Collection of services for JSON functionality

v1.0.0(10mo ago)01BSD-3-ClausePHPPHP &gt;=8.4CI passing

Since Jun 26Pushed 6mo agoCompare

[ Source](https://github.com/PHP-Alchemist/json)[ Packagist](https://packagist.org/packages/php-alchemist/json)[ RSS](/packages/php-alchemist-json/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (5)Versions (2)Used By (0)

PHP Alchemist JSON
==================

[](#php-alchemist-json)

Package: `php-alchemist/json`Current Version: v1.x -- (2025/06)

What?
-----

[](#what)

A basic library for working with json and being able to map json objects to a particular class

[![Unit Tests](https://github.com/PHP-Alchemist/json/actions/workflows/php.yml/badge.svg)](https://github.com/PHP-Alchemist/json/actions/workflows/php.yml)[![StyleCI](https://camo.githubusercontent.com/657b4831ac55094a5fc5b2cea85b784fb484d7f9f0029043949e123b8c3930dc/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f313030373237373232362f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/1007277226?branch=master)
[![Quality Gate Status](https://camo.githubusercontent.com/839773d1b3f1d206c245f08762f375cdd86e6ca8f590cafc2d0c2473dfe14409/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d5048502d416c6368656d6973745f6a736f6e266d65747269633d616c6572745f737461747573)](https://sonarcloud.io/summary/new_code?id=PHP-Alchemist_json)

Usage
-----

[](#usage)

The PHP Alchemist JSON library consists of two parts that can be used together or separately.

### JsonHydratorTrait

[](#jsonhydratortrait)

The first is a trait `PHPAlchemist\Json\Trait\JsonHydratorTrait` which has a single function called `hydrateFromJson()` which accepts a string called `$json` which is expected to be a JSON object. It then will loop through the object and looks for setter functions or if the property exists for each key and then sets the data appropriately on the object.

### JsonMapper

[](#jsonmapper)

The second is `PHPAlchemist\Json\Service\JsonMapper` which has a `map()` functino which will accept a JSON string (`$json`) and a classname (`$class`). This will validate the JSON and throw a `PHPAlchemist\Json\Exception\BadJsonException` if it is invalid. It will then instantiate a new class of the given type, check to see if the `hydrateFromJson()` exists. If it does, then it will use that otherwise it will then go through the same process to set the JSON keys via setter or public access.

#### Example

[](#example)

```
class Demo {
  public string $test;
  public string $doSomething;
}

$json   = '{"test":"blah","doSomething":"asdf"}';
$mapper = new PHPAlchemist\Json\Service\JsonMapper();
$asdf   = $mapper->map($json, Demo::class);

var_dump($asdf);
```

OUTPUT:

```
object(Demo)#1 (2) {
  ["test"]=>
  string(4) "blah"
  ["doSomething"]=>
  string(4) "asdf"
}
```

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance61

Regular maintenance activity

Popularity1

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

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

327d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1f32ae1f0bf9491a59f474478c6344e37034667512769884f00d31c8d1568757?d=identicon)[druid628](/maintainers/druid628)

---

Top Contributors

[![druid628](https://avatars.githubusercontent.com/u/522820?v=4)](https://github.com/druid628 "druid628 (23 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (5 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[terminal42/contao-url-rewrite

URL Rewrite bundle for Contao Open Source CMS

1595.3k3](/packages/terminal42-contao-url-rewrite)

PHPackages © 2026

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