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

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

asokol1981/json-schema-php
==========================

A PHP library for generating JSON Schema

v1.0.0(11mo ago)05MITPHPPHP &gt;=8.1CI passing

Since Jun 12Pushed 11mo agoCompare

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

READMEChangelogDependencies (2)Versions (2)Used By (0)

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

[](#json-schema-for-php)

[![tests](https://github.com/asokol1981/json-schema-php/workflows/tests/badge.svg)](https://github.com/asokol1981/json-schema-php/actions) [![codecov](https://camo.githubusercontent.com/29a1003aed458cb6d01e9ac77e0a505ce73773e6d864ac66fc38806d0c21bdad/68747470733a2f2f636f6465636f762e696f2f67682f61736f6b6f6c313938312f6a736f6e2d736368656d612d7068702f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/gh/asokol1981/json-schema-php) [![downloads](https://camo.githubusercontent.com/66bb40ebf91b4668c8921aa545853b21152e9dcad9a31c97e26b4f9a8fa7a1c0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f61736f6b6f6c313938312f6a736f6e2d736368656d612d7068702e737667)](https://packagist.org/packages/asokol1981/json-schema-php)

**json-schema-php** is an object-oriented PHP library for generating [JSON Schema](https://json-schema.org/) documents (Draft-07).

It allows you to programmatically build JSON schemas using a fluent, expressive API — no need to manually write arrays or JSON.

---

Features
--------

[](#features)

- Full support for JSON Schema Draft-07
- Fluent interface for intuitive schema building
- Support for all schema types:
    - object, array, string, number, integer, boolean, null
    - enum, const, ref, if/then/else, not, allOf, anyOf, oneOf
- Schema composition and nesting
- JSON serialization via toArray() or json\_encode()

---

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

[](#installation)

### Composer

[](#composer)

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

### VCS

[](#vcs)

If the package is not available on Packagist, you can install it by adding the following to your `composer.json`:

```
{
  "repositories": [
    {
      "type": "vcs",
      "url": "https://github.com/asokol1981/json-schema-php"
    }
  ],
  "require": {
    "asokol1981/json-schema-php": "dev-main"
  }
}
```

Then run:

```
composer update
```

⚠️ Make sure your project allows the dev-main version or use a specific tag (e.g. ^1.0) once available.

Usage
-----

[](#usage)

```
use ASokol1981\JsonSchema\Draft07\ObjectSchema;
use ASokol1981\JsonSchema\Draft07\StringSchema;
use ASokol1981\JsonSchema\Draft07\IntegerSchema;

$schema = (new ObjectSchema([
    'name' => (new StringSchema())->minLength(1),
    'age' => (new IntegerSchema())->minimum(0)
]))->setRequired('name');

echo json_encode($schema, JSON_PRETTY_PRINT);
```

Output:

```
{
  "type": "object",
  "properties": {
    "name": {
      "type": "string",
      "minLength": 1
    },
    "age": {
      "type": "integer",
      "minimum": 0
    }
  },
  "required": ["name"]
}
```

Directory Structure
-------------------

[](#directory-structure)

Schemas are organized under the ASokol1981\\JsonSchema\\Draft07 namespace, including:

- StringSchema
- ObjectSchema
- ArraySchema
- AllOfSchema, AnyOfSchema, NotSchema, RefSchema, etc.

🛠️ Makefile Commands
--------------------

[](#️-makefile-commands)

To simplify local development, the following `make` commands are available:

### 📦 Installation

[](#-installation)

```
make install
```

Builds the Docker container, starts it in the background, and installs Composer dependencies.

---

### 🏗️ Build Image

[](#️-build-image)

```
make build
```

Builds the Docker image with the tag `asokol1981/json-schema-php`.

---

### ▶️ Start Container

[](#️-start-container)

```
make start
```

Starts the container in detached mode.

---

### ⏹️ Stop Container

[](#️-stop-container)

```
make stop
```

Stops and removes the container (volumes are preserved).

---

### 🧹 Uninstall

[](#-uninstall)

```
make uninstall
```

Stops and removes the container, associated volumes, and the Docker image.

---

### 🐚 Shell Access

[](#-shell-access)

```
make exec -- bash
```

Runs a command inside the container. Be sure to use `--` to separate `make` arguments from the actual command:

```
make exec -- php -v
```

---

### 🎼 Composer

[](#-composer)

```
make composer -- require --dev phpunit/phpunit
```

Executes a Composer command inside the container. Example: install PHPUnit as a dev dependency.

---

### ✅ Run Tests

[](#-run-tests)

```
make test
```

Runs tests and shows code coverage summary in the terminal.

---

### 📊 HTML Coverage Report

[](#-html-coverage-report)

```
make coverage
```

Generates a code coverage report in HTML format and saves it in the `coverage/` directory.

---

### 🧱 Artisan

[](#-artisan)

```
make artisan -- list
```

Executes an Artisan command inside the container.

---

### 🧹 Code Style Fix

[](#-code-style-fix)

```
make php-cs-fixer
```

Runs PHP-CS-Fixer inside the container to automatically fix coding style issues according to the defined `.php-cs-fixer.dist.php` configuration.

---

### ✅ Validate Codecov Configuration

[](#-validate-codecov-configuration)

You can validate `codecov.yml` configuration using:

```
make codecov-validate
```

This command checks the syntax and structure of the `codecov.yml` file using Codecov’s validation API. It helps catch errors before pushing changes.

---

**ℹ️ Note:**When passing arguments to `exec`, `composer`, `artisan`, `test`, or `coverage` targets, **always prefix them with `--`** so `make` doesn't interpret them as its own flags.

Roadmap
-------

[](#roadmap)

- Support for newer drafts (e.g. 2020-12)

License
-------

[](#license)

MIT © [asokol1981](https://github.com/asokol1981)

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance51

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity45

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

Unknown

Total

1

Last Release

341d ago

### Community

Maintainers

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

---

Top Contributors

[![asokol1981](https://avatars.githubusercontent.com/u/11194728?v=4)](https://github.com/asokol1981 "asokol1981 (3 commits)")

---

Tags

phpjsonschema

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[adhocore/json-fixer

Fix/repair truncated JSON data

51543.2k2](/packages/adhocore-json-fixer)[blancks/fast-jsonpatch-php

Class designed to efficiently handle JSON Patch operations in accordance with the RFC 6902 specification

396.4k](/packages/blancks-fast-jsonpatch-php)[open-code-modeling/json-schema-to-php

Parses JSON schema files and provides an API to easily generate code from JSON schema.

111.0k2](/packages/open-code-modeling-json-schema-to-php)[josantonius/json

PHP simple library for managing Json files.

1621.6k10](/packages/josantonius-json)

PHPackages © 2026

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