PHPackages                             cortexphp/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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. cortexphp/json-schema

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

cortexphp/json-schema
=====================

A fluent JSON Schema builder for PHP

1.3.0(3w ago)587.4k↑34.9%1MITPHPPHP ^8.3CI passing

Since Jan 17Pushed 1w ago1 watchersCompare

[ Source](https://github.com/cortexphp/json-schema)[ Packagist](https://packagist.org/packages/cortexphp/json-schema)[ Docs](https://github.com/cortexphp/json-schema)[ RSS](/packages/cortexphp-json-schema/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (10)Dependencies (16)Versions (16)Used By (1)

Fluently build and validate JSON Schemas
========================================

[](#fluently-build-and-validate-json-schemas)

[![Latest Version](https://camo.githubusercontent.com/ddf3475e7a5c97c67263da5599f490a9374a8b6e44f935a672100f80037b8510/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636f727465787068702f6a736f6e2d736368656d612e7376673f7374796c653d666c61742d737175617265266c6f676f3d636f6d706f736572)](https://packagist.org/packages/cortexphp/json-schema)[![GitHub Actions Test Workflow Status](https://camo.githubusercontent.com/5f8afb97b7d0bb0dd957b411178c4bce2652c8d495b2d86016c9985d609ca04a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f636f727465787068702f6a736f6e2d736368656d612f72756e2d74657374732e796d6c3f7374796c653d666c61742d737175617265266c6f676f3d676974687562)](https://camo.githubusercontent.com/5f8afb97b7d0bb0dd957b411178c4bce2652c8d495b2d86016c9985d609ca04a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f636f727465787068702f6a736f6e2d736368656d612f72756e2d74657374732e796d6c3f7374796c653d666c61742d737175617265266c6f676f3d676974687562)[![GitHub License](https://camo.githubusercontent.com/19d74b63be2fe89df0293139ce1183257aba07a13fe101ba4744fab69b0075ad/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f636f727465787068702f6a736f6e2d736368656d613f7374796c653d666c61742d737175617265266c6f676f3d676974687562)](https://camo.githubusercontent.com/19d74b63be2fe89df0293139ce1183257aba07a13fe101ba4744fab69b0075ad/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f636f727465787068702f6a736f6e2d736368656d613f7374796c653d666c61742d737175617265266c6f676f3d676974687562)

[What is JSON Schema?](https://json-schema.org/overview/what-is-jsonschema)

Features
--------

[](#features)

- 🏗️ **Fluent Builder API** - Build JSON Schemas using an intuitive fluent interface
- 📝 **Multi-Version Support** - Support for JSON Schema Draft-06, Draft-07, Draft 2019-09, and Draft 2020-12
- ✅ **Validation** - Validate data against schemas with detailed error messages
- 🤝 **Conditional Schemas** - Support for if/then/else, allOf, anyOf, and not conditions
- 🔄 **Reflection** - Generate schemas from PHP classes, enums, and closures — including docblock array generics and constructor property promotion
- 💪 **Type Safety** - Built with PHP 8.3+ features and strict typing
- 🔍 **Version-Aware Features** - Automatic validation of version-specific features with helpful error messages

JSON Schema Version Support
---------------------------

[](#json-schema-version-support)

This package supports multiple JSON Schema specification versions with automatic feature validation:

### Supported Versions

[](#supported-versions)

- **Draft 2020-12** - (Default) Latest version with `prefixItems`, dynamic references, and format vocabularies
- **Draft 2019-09** - Adds advanced features like `$defs`, `unevaluatedProperties`, `deprecated`
- **Draft-07** (2018) - Legacy version with broad tool compatibility
- **Draft-06** (2017) - Legacy version for maximum compatibility with older tooling

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

[](#requirements)

- PHP 8.3+

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

[](#installation)

```
composer require cortexphp/json-schema
```

Quick Start
-----------

[](#quick-start)

```
use Cortex\JsonSchema\Schema;
use Cortex\JsonSchema\Enums\SchemaFormat;

// Create a schema
$schema = Schema::object('user')
    ->description('User schema')
    ->properties(
        Schema::string('name')
            ->minLength(2)
            ->maxLength(100)
            ->required(),
        Schema::string('email')
            ->format(SchemaFormat::Email)
            ->required(),
        Schema::integer('age')
            ->minimum(18)
            ->maximum(150),
        Schema::boolean('active')
            ->default(true),
        Schema::object('settings')
            ->additionalProperties(false)
            ->properties(
                Schema::string('theme')
                    ->enum(['light', 'dark']),
            ),
    );

$data = [
    'name' => 'John Doe',
    'email' => 'john@example.com',
    'age' => 30,
    'active' => true,
    'settings' => [
        'theme' => 'light',
    ],
];

if ($schema->isValid($data)) {
    echo "Valid!";
} else {
    try {
        $schema->validate($data);
    } catch (\Cortex\JsonSchema\Exceptions\SchemaException $e) {
        echo $e->getMessage();
    }
}

// Convert to array
$schema->toArray();

// Convert to JSON string
echo $schema->toJson(JSON_PRETTY_PRINT);
```

Documentation
-------------

[](#documentation)

📚 **[View Full Documentation →](https://docs.cortexphp.com/json-schema)**

Credits
-------

[](#credits)

- [Sean Tymon](https://github.com/tymondesigns)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

56

—

FairBetter than 97% of packages

Maintenance97

Actively maintained with recent releases

Popularity37

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 92.6% 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 ~46 days

Recently: every ~35 days

Total

12

Last Release

22d ago

Major Versions

0.6.0 → 1.0.02026-01-23

### Community

Maintainers

![](https://www.gravatar.com/avatar/2730d341811c79252a25178ab52ee3a83a857cf66b409e9691ecd3e89b6307e0?d=identicon)[tymondesigns](/maintainers/tymondesigns)

---

Top Contributors

[![tymondesigns](https://avatars.githubusercontent.com/u/1801923?v=4)](https://github.com/tymondesigns "tymondesigns (75 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (6 commits)")

---

Tags

json-schemaphpzodjsonschemajson-schemacortexzod

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleECS

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[justinrainbow/json-schema

A library to validate a json schema.

3.6k334.7M790](/packages/justinrainbow-json-schema)[jms/serializer

Library for (de-)serializing data of any complexity; supports XML, and JSON.

2.3k141.9M928](/packages/jms-serializer)[hasbridge/json-schema-validator

PHP 5.3 implementation of json schema validation

124460.4k3](/packages/hasbridge-json-schema-validator)[psx/schema

Parse and generate data schema formats

57245.5k24](/packages/psx-schema)[juststeveking/resume-php

A PHP library for building and working with the JSON resume schema.

1061.1k](/packages/juststeveking-resume-php)

PHPackages © 2026

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