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

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

evaisse/php-json-schema-generator
=================================

A JSON Schema Generator.

v2.1.0(3y ago)20298.5k—8.9%111MITPHPPHP &gt;=5.6.0

Since Aug 15Pushed 3y ago1 watchersCompare

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

READMEChangelogDependencies (4)Versions (11)Used By (1)

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

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

[![Build Status](https://camo.githubusercontent.com/55fcf3a46828dd2cf6b50593c3173bcf29fba07e1d44d3781de717d599be9630/68747470733a2f2f7472617669732d63692e6f72672f657661697373652f7068702d6a736f6e2d736368656d612d67656e657261746f722e7376673f6272616e63683d6d617374657223)](https://camo.githubusercontent.com/55fcf3a46828dd2cf6b50593c3173bcf29fba07e1d44d3781de717d599be9630/68747470733a2f2f7472617669732d63692e6f72672f657661697373652f7068702d6a736f6e2d736368656d612d67656e657261746f722e7376673f6272616e63683d6d617374657223)[![codecov](https://camo.githubusercontent.com/81812713e49416fd9ef1998da397554144456747d82ad023c431422c4ae1842b/68747470733a2f2f636f6465636f762e696f2f67682f657661697373652f7068702d6a736f6e2d736368656d612d67656e657261746f722f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/evaisse/php-json-schema-generator)

Originaly 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 evaisse/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

40

—

FairBetter than 88% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity45

Moderate usage in the ecosystem

Community17

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 83.3% 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 ~197 days

Recently: every ~443 days

Total

10

Last Release

1425d ago

Major Versions

v0.1.1 → v1.0.02017-08-16

v1.0.0 → v2.0.02017-08-16

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

v1.0.0PHP &gt;=5.6.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/1f8765f0d4bc19fa776ddc03f0eb9aad8c1f2ed72e3e0b9164ff3f496c6fb001?d=identicon)[evaisse](/maintainers/evaisse)

---

Top Contributors

[![solvire](https://avatars.githubusercontent.com/u/1051614?v=4)](https://github.com/solvire "solvire (15 commits)")[![evaisse](https://avatars.githubusercontent.com/u/28737?v=4)](https://github.com/evaisse "evaisse (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/evaisse-php-json-schema-generator/health.svg)

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

###  Alternatives

[opis/json-schema

Json Schema Validator for PHP

64736.9M186](/packages/opis-json-schema)[romaricdrigon/metayaml

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

103306.5k8](/packages/romaricdrigon-metayaml)[romegasoftware/laravel-schema-generator

Generate TypeScript Zod validation schemas from Laravel validation rules

288.2k](/packages/romegasoftware-laravel-schema-generator)

PHPackages © 2026

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