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

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

openregion/php-json-schema-generator
====================================

A JSON Schema Generator.

2.2.0(2y ago)16.4kMITPHPPHP &gt;=7.4.0

Since Aug 15Pushed 2y agoCompare

[ Source](https://github.com/openregion/php-json-schema-generator)[ Packagist](https://packagist.org/packages/openregion/php-json-schema-generator)[ Docs](https://github.com/openregion/php-json-schema-generator)[ RSS](/packages/openregion-php-json-schema-generator/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (3)Dependencies (5)Versions (13)Used By (0)

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

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

[![Build Status](https://camo.githubusercontent.com/af6ba3a68c45fa5821e5929c8e0d705d07bb3f8033e61caa9cf63f4385d5058f/68747470733a2f2f7472617669732d63692e6f72672f6f70656e726567696f6e2f7068702d6a736f6e2d736368656d612d67656e657261746f722e7376673f6272616e63683d6d617374657223)](https://camo.githubusercontent.com/af6ba3a68c45fa5821e5929c8e0d705d07bb3f8033e61caa9cf63f4385d5058f/68747470733a2f2f7472617669732d63692e6f72672f6f70656e726567696f6e2f7068702d6a736f6e2d736368656d612d67656e657261746f722e7376673f6272616e63683d6d617374657223)[![codecov](https://camo.githubusercontent.com/e0ca1b8daa39717ee28bfadc2ed99930f2947f13343070b4f86dd30bbe0fc728/68747470733a2f2f636f6465636f762e696f2f67682f6f70656e726567696f6e2f7068702d6a736f6e2d736368656d612d67656e657261746f722f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/openregion/php-json-schema-generator)

Forked from [evaisse/php-json-schema-generator](https://github.com/evaisse/php-json-schema-generator)

Originally forked from [solvire/php-json-schema-generator](https://github.com/solvire/php-json-schema-generator)

Introduction to json schema below (and tools) :

-  — reference
-  - validator (not 100% valid)
-  - use json schema to define REST API docs
-  - convenient editor for json schema

To validate your structure against a given schema, you can use :

-

Quickstart
----------

[](#quickstart)

Install using composer

```
composer require openregion/php-json-schema-generator
```

Most simple case

```
    $output = JSONSchemaGenerator\Generator::fromJson('{"a":{"b":2}');

    // $output ==> json string
    // {
    //   "$schema": "http://json-schema.org/draft-04/schema#",
    //   "type": "object",
    //   "properties": {
    //     "a": {
    //       "type": "object",
    //       "properties": {
    //         "b": {
    //           "type": "integer"
    //         }
    //       },
    //       "required": ["b"]
    //     }
    //   },
    //   "required": ["a"]
    // }
```

Default configuration values

```
    [
        'schema_id'                      => null,
        'properties_required_by_default' => true,
        'schema_uri'                     => 'http://json-schema.org/draft-04/schema#',
        'schema_title'                   => null,
        'schema_description'             => null,
        'schema_type'                    => null,
        "items_schema_collect_mode"      => 0,
        'schema_required_field_names'    => []
    ]
```

Advanced usage

```
    $result = Generator::fromJson($this->addressJson1, [
        'schema_id' => 'http://foo.bar/schema'
    ]);

    /*

      {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "id": "http://foo.bar/schema",
        "type": "object",
        "properties": {
          "a": {
            "type": "object",
            "id": "http://foo.bar/schema/a",
            "properties": {
              "b": {
                "id": "http://foo.bar/schema/a/b",
                "type": "integer"
              }
            }
          }
        }

    */

    // if you want items as strict lists instead of "anyOf" type
    $result = Generator::fromJson($this->addressJson1, [
        'schema_id'                      => 'http://bar.foo/schema2',
        'schema_title'                   => 'coucouc',
        'schema_description'             => 'desc',
        "items_schema_collect_mode"      => Definition::ITEMS_AS_LIST,
    ]);

    /*
        {
            "$schema":"http:\/\/json-schema.org\/draft-04\/schema#",
            ...
            "properties": {
                "phoneNumber":{
                    "id":"http:\/\/bar.foo\/schema2\/phoneNumber",
                    "type":"array",
                    "items": [
                        {"id":"http:\/\/bar.foo\/schema2\/0",...},
                        {"id":"http:\/\/bar.foo\/schema2\/1",...}}
    */
```

For more advanced usage, see `tests/JSONSchemaGenerator/Tests/GeneratorTest.php`

Testing
-------

[](#testing)

just run phpunit through

```
    composer test
```

debug with

```
    DEBUG=true composer test -- --filter="SearchWord" # for filtering *SearchWord* test case with output debugging
```

Roadmap
-------

[](#roadmap)

- Adjust schema comparison using re-ordering of properties to compare two schema against their semantic values instead of just comparing their JSON form. For example `{ a: 1, b: 2 }`, and `{ b: 2, a: 1 }`should result in the same schema.
- provide an option to allow null values in most fields `("type": ["string", "null"]}`

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 55.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 ~218 days

Recently: every ~600 days

Total

12

Last Release

831d ago

Major Versions

v0.1.1 → v1.0.02017-08-16

v1.0.0 → v2.0.02017-08-16

PHP version history (3 changes)v0.1.1PHP &gt;=5.4.0

v1.0.0PHP &gt;=5.6.0

v2.1.0PHP &gt;=7.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/479efafa1b1c6b0250d79500e7ef206cc0f55c99bf1784c06fee04d8911a0a23?d=identicon)[openregion](/maintainers/openregion)

---

Top Contributors

[![solvire](https://avatars.githubusercontent.com/u/1051614?v=4)](https://github.com/solvire "solvire (15 commits)")[![Gruven](https://avatars.githubusercontent.com/u/410058?v=4)](https://github.com/Gruven "Gruven (7 commits)")[![evaisse](https://avatars.githubusercontent.com/u/28737?v=4)](https://github.com/evaisse "evaisse (2 commits)")[![tbl0605](https://avatars.githubusercontent.com/u/3315731?v=4)](https://github.com/tbl0605 "tbl0605 (2 commits)")[![ryden54](https://avatars.githubusercontent.com/u/4123392?v=4)](https://github.com/ryden54 "ryden54 (1 commits)")

---

Tags

phpjsonschemavalidationparsergenerator

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[evaisse/php-json-schema-generator

A JSON Schema Generator.

18310.5k1](/packages/evaisse-php-json-schema-generator)[opis/json-schema

Json Schema Validator for PHP

64941.2M259](/packages/opis-json-schema)[romaricdrigon/metayaml

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

103311.2k8](/packages/romaricdrigon-metayaml)

PHPackages © 2026

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