PHPackages                             021/json-schema - 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. 021/json-schema

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

021/json-schema
===============

Object-Oriented JSON Schema Generation

v1.0.1(1y ago)2146MITPHPPHP &gt;=8.1

Since Nov 23Pushed 1y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (3)Used By (0)

Object-Oriented JSON Schema Generation in PHP
=============================================

[](#object-oriented-json-schema-generation-in-php)

[![Total Downloads](https://camo.githubusercontent.com/ab016702008f56d9a4feaec368cc5dd6fd46d6565190f9be41e94eaa443bec40/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f3032312f6a736f6e2d736368656d61)](https://packagist.org/packages/021/json-schema)[![Latest Stable Version](https://camo.githubusercontent.com/aa63c023077f35d6c20414ac9552ff8ad3f64f438aec2dd6b29edae3ad0b422c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f3032312f6a736f6e2d736368656d61)](https://packagist.org/packages/021/json-schema)[![License](https://camo.githubusercontent.com/88f0c7dd396fbc320e7157572ab273c314bfb16092f5fb55b706fa0be68d5fec/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f3032312f6a736f6e2d736368656d61)](https://packagist.org/packages/021/json-schema)

This library provides a way to generate JSON schemas in PHP using an object-oriented approach. It is inspired by the [JSON Schema](https://json-schema.org/) standard and aims to provide a way to generate JSON schemas in a more readable and maintainable way.

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

[](#installation)

```
composer require 021/json-schema
```

Usage
-----

[](#usage)

```
use O21\JsonSchema\Schema;
use O21\JsonSchema\Enums\Type;
use O21\JsonSchema\Enums\Format;

$schema = new Schema(
    schema: 'http://json-schema.org/draft-07/schema#',
    type: Type::OBJECT,
    properties: [
        'name' => new Schema(
            type: Type::STRING,
            minLength: 1,
            maxLength: 255
        ),
        'age' => new Schema(
            type: Type::INTEGER,
            minimum: 0,
            maximum: 150
        ),
        'addresses' => new Schema(
            type: Type::ARRAY,
            items: new Schema(
                type: Type::OBJECT,
                properties: [
                    'street' => new Schema(
                        type: Type::STRING,
                        minLength: 1,
                        maxLength: 255
                    ),
                    'city' => new Schema(
                        type: Type::STRING,
                        minLength: 1,
                        maxLength: 255
                    ),
                    'zip' => new Schema(
                        type: Type::STRING,
                        pattern: '^[0-9]{5}$'
                    )
                ],
                required: ['street', 'city', 'zip']
            ),
        ),
        'email' => new Schema(
            type: Type::STRING,
            format: Format::EMAIL
        ),
        'phone' => new Schema(
            type: Type::STRING,
            pattern: '^\+[0-9]{1,3}\.[0-9]{1,14}$'
        ),
        'is_active' => new Schema(
            type: Type::BOOLEAN,
            default: true,
        ),
    ]
);
// Convert the schema to JSON
$json = $schema->toJson();
// Convert the schema to an object
$obj = $schema->toObject();
```

### Transform

[](#transform)

Almost all properties listed on the [JSON Schema reference](https://json-schema.org/understanding-json-schema/reference) are supported, but if some properties are missing in the current version of the library or you want to add your own, you can use the transform method. It is called when the `Schema` class is transformed into the `stdClass` class to generate JSON from it:

```
use O21\JsonSchema\Schema;

$schema = new Schema(
    transform: function (stdClass $schema): void {
        $schema->foo = 'bar';
    }
);
```

Support Us
----------

[](#support-us)

- **Bitcoin**: 1G4U12A7VVVaUrmj4KmNt4C5SaDmCXuW49
- **Litecoin**: LXjysogo9AHiNE7AnUm4zjprDzCCWVESai
- **Ethereum**: 0xd23B42D0A84aB51a264953f1a9c9A393c5Ffe4A1
- **Tron**: TWEcfzu2UAPsbotZJh8DrEpvdZGho79jTg

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

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

Total

2

Last Release

541d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/850e7a3d7b73d4aca00b33bfd13c33b97a8bec35d3b889d50cc0eec3b26eb337?d=identicon)[021-projects](/maintainers/021-projects)

---

Top Contributors

[![021-projects](https://avatars.githubusercontent.com/u/20326979?v=4)](https://github.com/021-projects "021-projects (5 commits)")

### Embed Badge

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

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

###  Alternatives

[vcian/pulse-active-sessions

A Laravel Pulse card to show active user session.

11469.2k](/packages/vcian-pulse-active-sessions)[norberttech/aceeditor-bundle

Bundle that integrate excellent JavaScript ace editor into Symfony Form.

28310.8k](/packages/norberttech-aceeditor-bundle)[tomloprod/radiance

A deterministic mesh gradient avatar generator for PHP.

1393.7k](/packages/tomloprod-radiance)[chefkoch/morphoji

A library to convert UTF-8 emoji characters to latin1 placeholders and vice versa.

14136.9k1](/packages/chefkoch-morphoji)[epessine/axis

Draw charts with a simple API on Laravel

265.6k](/packages/epessine-axis)

PHPackages © 2026

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