PHPackages                             specdocular/php-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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. specdocular/php-json-schema

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

specdocular/php-json-schema
===========================

PHP implementation of JSON Schema (Draft 2020-12)

v0.1.0(3mo ago)0567↓50%2MITPHPPHP ^8.2CI passing

Since Feb 12Pushed 2mo agoCompare

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

READMEChangelogDependencies (13)Versions (2)Used By (2)

PHP JSON Schema
===============

[](#php-json-schema)

[![Latest Version on Packagist](https://camo.githubusercontent.com/f661fa04d30658704ce8dbeacee2817910eef55464023663b12974697f32acb6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73706563646f63756c61722f7068702d6a736f6e2d736368656d612e737667)](https://packagist.org/packages/specdocular/php-json-schema)[![PHP Version](https://camo.githubusercontent.com/37fcb93982bf58fdadab52f550ccc39e9146cc08a5d1255b8128f54bf19de003/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f73706563646f63756c61722f7068702d6a736f6e2d736368656d612e737667)](https://packagist.org/packages/specdocular/php-json-schema)[![Tests](https://github.com/specdocular/php-json-schema/actions/workflows/tests.yml/badge.svg)](https://github.com/specdocular/php-json-schema/actions/workflows/tests.yml)[![codecov](https://camo.githubusercontent.com/1a57c946e1d2fad26549cfa1418bdf09583c35ac4419f1bfd625395e750ba886/68747470733a2f2f636f6465636f762e696f2f67682f73706563646f63756c61722f7068702d6a736f6e2d736368656d612f67726170682f62616467652e737667)](https://codecov.io/gh/specdocular/php-json-schema)[![Code Style](https://github.com/specdocular/php-json-schema/actions/workflows/php-cs-fixer.yml/badge.svg)](https://github.com/specdocular/php-json-schema/actions/workflows/php-cs-fixer.yml)

A type-safe, fluent PHP implementation of [JSON Schema Draft 2020-12](https://json-schema.org/draft/2020-12/json-schema-core).

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

[](#installation)

```
composer require specdocular/php-json-schema
```

Usage
-----

[](#usage)

Build JSON Schema definitions using a fluent, type-safe API:

```
use Specdocular\JsonSchema\Draft202012\StrictFluentDescriptor;
use Specdocular\JsonSchema\Draft202012\Keywords\Properties\Property;

$schema = StrictFluentDescriptor::object()
    ->properties(
        Property::create('name', StrictFluentDescriptor::string()->minLength(1)),
        Property::create('email', StrictFluentDescriptor::string()->format('email')),
        Property::create('age', StrictFluentDescriptor::integer()->minimum(0)),
    )
    ->required('name', 'email');

// Compile to array
$compiled = $schema->compile();

// Or encode directly to JSON
$json = json_encode($schema, JSON_PRETTY_PRINT);
```

### Strict vs Loose Descriptors

[](#strict-vs-loose-descriptors)

- **`StrictFluentDescriptor`** (recommended) — provides type-specific method autocomplete. Methods like `minLength()` are only available on string schemas, `minimum()` only on numeric schemas, etc.
- **`LooseFluentDescriptor`** — exposes all keywords on every schema. Useful when building schemas with multiple types.

Features
--------

[](#features)

- Full JSON Schema Draft 2020-12 support (all 50 keywords, 7 vocabularies)
- Type-safe fluent API with IDE autocomplete
- Extensible keyword and vocabulary system
- Built-in schema validation (`VocabularyValidator`, `MetaSchemaValidator`)
- Framework-agnostic — no dependencies on Laravel or any framework

> **Note:** This library builds JSON Schema definitions. It does not validate data against schemas — use a validation library like `justinrainbow/json-schema` for that.

Related Packages
----------------

[](#related-packages)

PackageDescription[specdocular/php-openapi](https://github.com/specdocular/php-openapi)Object-oriented OpenAPI 3.1.x builder (uses this package)[specdocular/laravel-rules-to-schema](https://github.com/specdocular/laravel-rules-to-schema)Convert Laravel validation rules to JSON Schema (uses this package)[specdocular/laravel-openapi](https://github.com/specdocular/laravel-openapi)Laravel integration for OpenAPI generationLicense
-------

[](#license)

MIT. See [LICENSE](LICENSE) for details.

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance83

Actively maintained with recent releases

Popularity15

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

95d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e05ce3549156452319c5fdfc014b5eb441e3a6148f1f4957fb863026ecc6f8a0?d=identicon)[mohammad-alavi](/maintainers/mohammad-alavi)

---

Top Contributors

[![Mohammad-Alavi](https://avatars.githubusercontent.com/u/24431504?v=4)](https://github.com/Mohammad-Alavi "Mohammad-Alavi (9 commits)")

---

Tags

jsonschemavalidationjson-schemadraft-2020-12

###  Code Quality

TestsPest

Static AnalysisPHPStan, Psalm, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[opis/json-schema

Json Schema Validator for PHP

64736.9M186](/packages/opis-json-schema)[geraintluff/jsv4

A (coercive) JSON Schema v4 Validator for PHP

115455.2k4](/packages/geraintluff-jsv4)[romaricdrigon/metayaml

Using \[Yaml|Xml|json\] schemas files to validate \[Yaml|Xml|json\]

103306.5k8](/packages/romaricdrigon-metayaml)[evaisse/php-json-schema-generator

A JSON Schema Generator.

20298.5k1](/packages/evaisse-php-json-schema-generator)

PHPackages © 2026

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