PHPackages                             pandaleague/jsonschemabuilder - 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. pandaleague/jsonschemabuilder

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

pandaleague/jsonschemabuilder
=============================

v0.3.0(2w ago)13.2k—2.9%MITPHPPHP ^8.3CI passing

Since Feb 6Pushed 2w ago1 watchersCompare

[ Source](https://github.com/pandaleague/JsonSchemaBuilder)[ Packagist](https://packagist.org/packages/pandaleague/jsonschemabuilder)[ RSS](/packages/pandaleague-jsonschemabuilder/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (9)Dependencies (3)Versions (14)Used By (0)

JsonSchemaBuilder
=================

[](#jsonschemabuilder)

A small, fluent PHP library for assembling [JSON Schema](https://json-schema.org/) documents as PHP arrays — ready to encode to JSON.

Requirements
------------

[](#requirements)

- PHP 8.3+
- `illuminate/contracts` ^11 || ^12

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

[](#installation)

```
composer require pandaleague/jsonschemabuilder
```

Quick example
-------------

[](#quick-example)

```
use PandaLeague\JsonSchemaBuilder\Factory;

$schema = Factory::obj()
    ->title('User')
    ->description('A registered user')
    ->property('id', Factory::num()->minimum(1))
    ->property('email', Factory::str()->format('email'))
    ->property('roles', Factory::arr()
        ->items(Factory::str()->enum(['admin', 'user']))
        ->uniqueItems(true)
    )
    ->required(['id', 'email'])
    ->additionalProperties(false);

echo json_encode($schema->toArray(), JSON_PRETTY_PRINT);
```

```
{
    "type": "object",
    "title": "User",
    "description": "A registered user",
    "properties": {
        "id":    { "type": "number", "minimum": 1 },
        "email": { "type": "string", "format": "email" },
        "roles": {
            "type": "array",
            "items": {
                "type": "string",
                "enum": ["admin", "user"]
            },
            "uniqueItems": true
        }
    },
    "additionalProperties": false,
    "required": ["id", "email"]
}
```

Types
-----

[](#types)

Every builder is created through `Factory` and returns a fluent instance. All builders implement `Illuminate\Contracts\Support\Arrayable`, so `toArray()` produces the final schema.

FactoryClassJSON Schema type`Factory::str()``aStr``string``Factory::num()``aNum``number``Factory::bool()``aBool``boolean``Factory::arr()``aArr``array``Factory::obj()``aObj``object``Factory::null()``aNull``null`### Shared keywords

[](#shared-keywords)

Available on every builder (via the `BaseType` trait):

- `id(string)`, `schema(string)`, `title(string)`, `description(string)`
- `enum(array)` — values must match the underlying type
- `anyOf(Type[])`, `allOf(Type[])`, `oneOf(Type[])`, `not(Type)`
- `ref(string)` — emitted as `$ref`
- `readOnly(bool)`, `writeOnly(bool)`, `nullable(bool)`
- `link(string $rel, string $href, string $title = '', string $method = 'GET')` — `$rel` is restricted to IANA-style relations (`self`, `create`, `edit`, `delete`, `replace`, `first`, `last`, `next`, `prev`, `collection`, `latest-version`, `search`, `up`)

### Strings — `aStr`

[](#strings--astr)

```
Factory::str()
    ->size(3, 32)            // minLength / maxLength
    ->pattern('^[a-z]+$')
    ->format('email')
    ->default('admin');
```

### Numbers — `aNum`

[](#numbers--anum)

```
Factory::num()
    ->minimum(0.5, exclusive: true)
    ->maximum(10.0)
    ->multipleOf(0.5)
    ->default(1.0);
```

### Arrays — `aArr`

[](#arrays--aarr)

```
Factory::arr()
    ->items(Factory::str())          // single schema, or
    ->items([Factory::str(), Factory::num()], additionalItems: false) // tuple
    ->size(1, 5)                     // minItems / maxItems
    ->uniqueItems(true);
```

### Objects — `aObj`

[](#objects--aobj)

```
Factory::obj()
    ->property('name', Factory::str())
    ->property('age',  Factory::num())
    ->required(['name'])
    ->additionalProperties(false)        // bool or Type
    ->size(1, 10)                        // minProperties / maxProperties
    ->propertyDependency('name', ['age'])
    ->patternProperty('^x-', Factory::str())
    ->propertyNames(Factory::str()->pattern('^[a-z]+$'));
```

### Booleans / null

[](#booleans--null)

```
Factory::bool()->default(true);
Factory::null();
```

Combining schemas
-----------------

[](#combining-schemas)

```
Factory::str()->anyOf([
    Factory::str()->format('email'),
    Factory::str()->pattern('^\+?[0-9]+$'),
]);
```

Development
-----------

[](#development)

Install dev dependencies and run the test suite:

```
composer install
composer test
```

License
-------

[](#license)

MIT

###  Health Score

55

—

FairBetter than 97% of packages

Maintenance96

Actively maintained with recent releases

Popularity23

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 92% 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 ~381 days

Recently: every ~614 days

Total

9

Last Release

19d ago

### Community

Maintainers

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

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

---

Top Contributors

[![Ed-leRoux](https://avatars.githubusercontent.com/u/10370397?v=4)](https://github.com/Ed-leRoux "Ed-leRoux (23 commits)")[![sgleave](https://avatars.githubusercontent.com/u/3275169?v=4)](https://github.com/sgleave "sgleave (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/pandaleague-jsonschemabuilder/health.svg)

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[illuminate/events

The Illuminate Events package.

13557.0M2.1k](/packages/illuminate-events)[illuminate/pagination

The Illuminate Pagination package.

12234.1M1.0k](/packages/illuminate-pagination)[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M195](/packages/laravel-ai)[illuminate/pipeline

The Illuminate Pipeline package.

9349.2M282](/packages/illuminate-pipeline)[illuminate/session

The Illuminate Session package.

9939.3M850](/packages/illuminate-session)

PHPackages © 2026

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