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

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

pxhub/php-json-schema-generator
===============================

A JSON Schema Generator.

v1.0.3(2y ago)01.3k↓25%MITPHPPHP &gt;=5.6.0

Since Sep 13Pushed 2y agoCompare

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

READMEChangelog (2)Dependencies (4)Versions (5)Used By (0)

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 [evaisse/php-json-schema-generator](https://github.com/evaisse/php-json-schema-generator)

#### List of changes:

[](#list-of-changes)

- Collect examples for each scalar type.
- Items properties merged to single list instead of 'anyOf' list.

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 properties list
$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

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 65.2% 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 ~32 days

Total

4

Last Release

880d ago

### Community

Maintainers

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

---

Top Contributors

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

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

###  Alternatives

[evaisse/php-json-schema-generator

A JSON Schema Generator.

20298.5k1](/packages/evaisse-php-json-schema-generator)[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)

PHPackages © 2026

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