PHPackages                             llm-agents/json-schema-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. llm-agents/json-schema-mapper

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

llm-agents/json-schema-mapper
=============================

JSON Schema to PHP Class Mapper for LLM Agents

1.2.0(9mo ago)435215MITPHPPHP ^8.3

Since Aug 28Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/llm-agents-php/schema-mapper)[ Packagist](https://packagist.org/packages/llm-agents/json-schema-mapper)[ RSS](/packages/llm-agents-json-schema-mapper/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (6)Versions (5)Used By (5)

JSON Schema Mapper for LLM Agents
=================================

[](#json-schema-mapper-for-llm-agents)

[![PHP](https://camo.githubusercontent.com/b2850ceb9a70a5f674c170c67de31ee9bf8ccc4470ce6033224b5771437d7457/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6c6c6d2d6167656e74732f6a736f6e2d736368656d612d6d61707065722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/llm-agents/json-schema-mapper)[![Latest Version on Packagist](https://camo.githubusercontent.com/26289c4c9c964bfde5c38bbc05b21e2e1a666d34f7241dcffc0af02142d57158/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c6c6d2d6167656e74732f6a736f6e2d736368656d612d6d61707065722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/llm-agents/json-schema-mapper)[![Total Downloads](https://camo.githubusercontent.com/256084a9a98b2c9ffc5de13ca1ebaff06569d96dcf9d65d05ed65b3aa0f9db43/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c6c6d2d6167656e74732f6a736f6e2d736368656d612d6d61707065722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/llm-agents/json-schema-mapper)

This package is a super handy JSON Schema Mapper for the LLM Agents project.

What's it all about?
--------------------

[](#whats-it-all-about)

This package gives you a nifty SchemaMapper that can:

- Convert PHP classes to JSON schemas
- Turn JSON data into PHP objects

Class Diagram
-------------

[](#class-diagram)

Here's a quick look at how the main components fit together:

 ```
classDiagram
    class SchemaMapperInterface {

        +toJsonSchema(string $class): array
        +toObject(string $json, ?string $class): object
    }
    class SchemaMapper {
        -generator: JsonSchemaGenerator
        -mapper: TreeMapper
        +toJsonSchema(string $class): array
        +toObject(string $json, ?string $class): object
    }
    SchemaMapperInterface  JsonSchemaGenerator
    SchemaMapper --> TreeMapper
```

      Loading Getting Started
---------------

[](#getting-started)

### Installation

[](#installation)

First things first, let's get this package installed:

```
composer require llm-agents/json-schema-mapper
```

### Setting it up in Spiral

[](#setting-it-up-in-spiral)

If you're using the Spiral framework (and why wouldn't you be? It's awesome!), you'll need to register the bootloader.

**Here's how:**

1. Open up your `app/src/Application/Kernel.php` file.
2. Add the `LLM\Agents\JsonSchema\Mapper\Integration\Spiral\SchemaMapperBootloader` to the `defineBootloaders()` method:

```
class Kernel extends \Spiral\Framework\Kernel
{
    // ...

    public function defineBootloaders(): array
    {
        return [
            // ... other bootloaders ...
            \LLM\Agents\JsonSchema\Mapper\Integration\Spiral\SchemaMapperBootloader::class,
        ];
    }
}
```

And that's it! The bootloader will take care of registering all the necessary components for you.

### Setting it up in Laravel

[](#setting-it-up-in-laravel)

If you're using the Laravel framework, you'll need to register the Service provider.

**Here's how:**

Just register the `LLM\Agents\JsonSchema\Mapper\Integration\Laravel\SchemaMapperServiceProvider`

And that's it! The service provider will take care of registering all the necessary components for you.

How to Use It
-------------

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

### Converting a PHP Class to JSON Schema

[](#converting-a-php-class-to-json-schema)

Let's say you have a `User` class and you want to get its JSON schema:

```
use LLM\Agents\JsonSchema\Mapper\SchemaMapperInterface;

class UserController
{
    public function __construct(
        private SchemaMapperInterface $schemaMapper
    ) {}

    public function getUserSchema(): array
    {
        return $this->schemaMapper->toJsonSchema(User::class);
    }
}
```

### Converting JSON to a PHP Object

[](#converting-json-to-a-php-object)

Got some JSON data that you want to turn into a PHP object? No problem:

```
use LLM\Agents\JsonSchema\Mapper\SchemaMapperInterface;

class UserService
{
    public function __construct(
        private SchemaMapperInterface $schemaMapper
    ) {}

    public function createUserFromJson(string $json): User
    {
        return $this->schemaMapper->toObject($json, User::class);
    }
}
```

Contributing
------------

[](#contributing)

We'd love your help to make this package even better! Here's how you can contribute:

1. Fork the repository
2. Write some awesome code
3. Create a new Pull Request

Please make sure your code follows PSR-12 coding standards and include tests for any new features.

License
-------

[](#license)

This package is open-sourced software licensed under the MIT license. Feel free to use it, modify it, and share it!

---

That's all, folks! If you have any questions or run into any issues, don't hesitate to open an issue on GitHub.

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance58

Moderate activity, may be stable

Popularity19

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity58

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

Total

4

Last Release

270d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/773481?v=4)[Pavel Buchnev](/maintainers/butschster)[@butschster](https://github.com/butschster)

---

Top Contributors

[![butschster](https://avatars.githubusercontent.com/u/773481?v=4)](https://github.com/butschster "butschster (11 commits)")

---

Tags

json-schema-generatorllm-agentsphpphp8

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[setono/editorjs-php

PHP library for handling data from the EditorJS

4255.2k1](/packages/setono-editorjs-php)[koalafacade/diamond-console

Laravel Package for generate DDD structure easily for your projects

641.4k](/packages/koalafacade-diamond-console)[mention/retry

A Retry library for PHP

1324.5k](/packages/mention-retry)

PHPackages © 2026

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