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)2210MITPHPPHP &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 62% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

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

587d 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

[ethercreative/yii2-ip-ratelimiter

Allow guest clients to be rate limited, using their IP as the identifier.

36145.7k1](/packages/ethercreative-yii2-ip-ratelimiter)[optimus/distributed-laravel

3183.9k4](/packages/optimus-distributed-laravel)[funiq/geophp

Open-source native PHP library for doing geometry operations. Can read and write a wide variety of formats: (E)WKT, (E)WKB, TWKB, GeoJSON, KML, GPX, GeoRSS. Works with all Simple-Feature geometries (Point, LineString, Polygon...) and can be used to get centroids, bounding-boxes, area, etc.

22117.8k1](/packages/funiq-geophp)

PHPackages © 2026

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