https://github.com/dunglas/php-to-json-schema
Creates a JSON Schema from a PHP class
https://github.com/dunglas/php-to-json-schema
json json-schema php
Last synced: 8 months ago
JSON representation
Creates a JSON Schema from a PHP class
- Host: GitHub
- URL: https://github.com/dunglas/php-to-json-schema
- Owner: dunglas
- License: mit
- Archived: true
- Created: 2016-01-11T14:46:51.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2022-01-10T20:41:18.000Z (almost 4 years ago)
- Last Synced: 2025-03-17T23:33:50.855Z (9 months ago)
- Topics: json, json-schema, php
- Language: PHP
- Homepage: https://dunglas.fr
- Size: 8.79 KB
- Stars: 32
- Watchers: 2
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PHP to JSON Schema
**This library is deprecated, use [API Platform JSON Schema](https://api-platform.com/docs/core/json-schema/) instead.**
Creates a JSON Schema from a PHP entity. Useful to ensure that a given JSON document will
be deserialized properly in an object graph.
[](https://travis-ci.org/dunglas/php-to-json-schema)
[](https://scrutinizer-ci.com/g/dunglas/php-to-json-schema/?branch=master)
[](https://insight.sensiolabs.com/projects/315bcf00-2a7d-4185-9290-c02c67c731d7)
## Installation
Use [https://getcomposer.org](Composer) to install the library:
```
composer require dunglas/php-to-json-schema
```
## Usage
```php
use Dunglas\PhpToJsonSchema\Generator;
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
use Symfony\Component\PropertyInfo\PropertyInfoExtractor;
class MyClass
{
private $foo;
private $bar;
public function setFoo(string $foo)
{
$this->foo = $foo;
}
public function setBar(float $bar = null)
{
$this->bar = $bar;
}
// ...
}
$reflectionExtractor = new ReflectionExtractor();
$propertyInfoExtractor = new PropertyInfoExtractor([$reflectionExtractor], [$reflectionExtractor], [], [$reflectionExtractor]);
$generator = new Generator($propertyInfoExtractor);
echo json_encode($generator->generate(MyClass::class));
```
## Credits
Created by [Kévin Dunglas](https://dunglas.fr).