PHPackages                             swaggest/json-schema-maker - 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. swaggest/json-schema-maker

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

swaggest/json-schema-maker
==========================

Instance to JSON schema and back

v0.3.7(4y ago)1066.9k↓32.7%2MITPHPPHP &gt;=5.6.0CI failing

Since Oct 4Pushed 4y agoCompare

[ Source](https://github.com/swaggest/json-schema-maker)[ Packagist](https://packagist.org/packages/swaggest/json-schema-maker)[ Docs](https://github.com/swaggest/json-schema-maker)[ RSS](/packages/swaggest-json-schema-maker/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (2)Versions (14)Used By (2)

JSON Schema Maker
=================

[](#json-schema-maker)

[![Build Status](https://camo.githubusercontent.com/3206269da6826bc94f7b2e2bc1335abc349068220be590a8dc5ee43b2e710d5a/68747470733a2f2f7472617669732d63692e6f72672f73776167676573742f6a736f6e2d736368656d612d6d616b65722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/swaggest/json-schema-maker)[![Code Climate](https://camo.githubusercontent.com/47e56f6ab16a061d5c9733a35b73317c94bfbcf1ae6b7d2816a2af60920b02df/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f73776167676573742f6a736f6e2d736368656d612d6d616b65722f6261646765732f6770612e737667)](https://codeclimate.com/github/swaggest/json-schema-maker)[![codecov](https://camo.githubusercontent.com/c9d5445ab346ab1b89c09b4ebb89b7a68add6707b4aac6b756e247a45b201594/68747470733a2f2f636f6465636f762e696f2f67682f73776167676573742f6a736f6e2d736368656d612d6d616b65722f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/swaggest/json-schema-maker)

Create JSON Schema from instance values and vice versa.

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

[](#installation)

```
composer require swaggest/json-schema-maker

```

Usage
-----

[](#usage)

### CLI

[](#cli)

[`json-cli build-schema`](https://github.com/swaggest/json-cli#buildschema)

```
v1.7.8 json-cli build-schema
JSON CLI tool, https://github.com/swaggest/json-cli
Usage:
   json-cli build-schema  [schema]
   data     Path to data (JSON/YAML)
   schema   Path to parent schema

Options:
   --ptr-in-schema            JSON pointer to structure in root schema, default #
   --ptr-in-data                JSON pointer to structure in data, default #
   --jsonl                                 Data is a stream of JSON Lines
   --use-nullable                          Use `nullable: true` instead of `type: null`, OAS 3.0 compatibility
   --use-xnullable                         Use `x-nullable: true` instead of `type: null`, Swagger 2.0 compatibility
   --defs-ptr                     Location to put new definitions. default: "#/definitions/"
   --collect-examples                      Collect scalar values example
   --heuristic-required                    Mark properties that are available in all samples as `required`.
   --additional-data    Additional paths to data
   --pretty                                Pretty-print result JSON
   --output                        Path to output result, default STDOUT
   --to-yaml                               Output in YAML format
   --to-serialized                         Output in PHP serialized format

```

Basic example:

```
json-cli build-schema tests/assets/original.json

{"properties":{"key1":{"items":{"type":"integer"},"type":"array"},"key2":{"type":"integer"},"key3":{"$ref":"#/definitions/key3"},"key4":{"items":{"$ref":"#/definitions/key4.element"},"type":"array"}},"type":"object","definitions":{"key3":{"properties":{"sub0":{"type":"integer"},"sub1":{"type":"string"},"sub2":{"type":"string"}},"type":"object"},"key4.element":{"properties":{"a":{"type":"integer"},"b":{"type":"boolean"}},"type":"object"}}}

```

Advanced example:

```
json-cli build-schema dump-responses.jsonl ./acme-service/swagger.json --ptr-in-schema "#/definitions/Orders" --jsonl --ptr-in-data "#/responseValue" --pretty --output swagger.json

```

Updates `swagger.json` with actual response samples provided in `dump-responses.jsonl`.

### Generating JSON schema based on instance values

[](#generating-json-schema-based-on-instance-values)

```
$instanceValue = json_decode(file_get_contents(__DIR__ . '/../resources/github-example.json'));
$schema = new \Swaggest\JsonSchema\Schema();
$f = new \Swaggest\JsonSchemaMaker\SchemaMaker($schema);
$f->options->upgradeIntToNumber = true; // Use `type: number` instead of `type: [integer, number]`.

$f->addInstanceValue($instanceValue);

$schemaJson = json_encode(\Swaggest\JsonSchema\Schema::export($schema));     // With object schemas extracted as definitions.
$schemaJsonInline = json_encode($schema);               // With inline object schemas.
```

See available [options](./src/Options.php).

See [example schemas](./tests/resources).

### Generating fake instance value based on JSON schema

[](#generating-fake-instance-value-based-on-json-schema)

```
mt_srand(1); // Optionally seed random generator for reproducible results.
$schema = \Swaggest\JsonSchema\Schema::import(json_decode(file_get_contents(__DIR__ . '/../resources/github-example-schema-with-examples.json')));

$instanceFaker = new \Swaggest\JsonSchemaMaker\InstanceFaker($schema);
$value = $instanceFaker->makeValue();
$anotherValue = $instanceFaker->makeValue();
```

See available [options](./src/Options.php).

See [example value](./tests/resources/github-example-fake-instance.json).

See also
--------

[](#see-also)

- [Quicktype](https://app.quicktype.io/).

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity50

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

Every ~63 days

Recently: every ~137 days

Total

13

Last Release

1709d ago

PHP version history (2 changes)v0.0.1PHP &gt;=5.5.0

v0.2.0PHP &gt;=5.6.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/27acbd2504e91c838d403112493d8ae7b584c2d8d2f2ea7a9762ef764e35bc8c?d=identicon)[vearutop](/maintainers/vearutop)

---

Top Contributors

[![vearutop](https://avatars.githubusercontent.com/u/1381436?v=4)](https://github.com/vearutop "vearutop (18 commits)")

---

Tags

json-schema

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/swaggest-json-schema-maker/health.svg)

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

###  Alternatives

[mck89/peast

Peast is PHP library that generates AST for JavaScript code

19139.2M47](/packages/mck89-peast)[firefly-iii/data-importer

Firefly III Data Import Tool.

8035.8k](/packages/firefly-iii-data-importer)[sauladam/shipment-tracker

Parses tracking information for several carriers, like UPS, USPS, DHL and GLS by simply scraping the data. No need for any kind of API access.

9843.5k](/packages/sauladam-shipment-tracker)[tcds-io/php-jackson

A lightweight, flexible object serializer for PHP, inspired by FasterXML/jackson

113.2k10](/packages/tcds-io-php-jackson)

PHPackages © 2026

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