A PHP package to make it easier create JSON schemas.

1.2.0 2021-07-08 15:41 UTC

This package is auto-updated.

Last update: 2023-11-08 20:41:47 UTC


JSON Schema Creator This is a simple PHP package to make it quick and easy to generate a JSON schema that can then be used for validation and documentation.

This tool was built primarily with the help of the documentation for JSON schemas at


composer require programster/json-schema-creator


require_once(__DIR__ . '/../vendor/autoload.php');

$name = new \Programster\JsonSchema\Types\StringType(name: "product_name", minLength: 3);
$barcode = new \Programster\JsonSchema\Types\StringType(name: "barcode", minLength: 12);
$description = new \Programster\JsonSchema\Types\StringType(name: "description", minLength: 12);

$requiredProperties = array(

$nonRequiredProprties = array(

$object = new Programster\JsonSchema\Types\ObjectType(
    new Programster\JsonSchema\PropertyCollection(...$requiredProperties, ...$nonRequiredProprties),
    new Programster\JsonSchema\RequiredPropertiesCollection(...$requiredProperties)

$schema = new \Programster\JsonSchema\Schema($object, "Product Schema", "A product definition");
print($schema) . PHP_EOL;

That would generate the following schema:

    "$schema": "",
    "$id": "Product Schema",
    "title": "A product definition",
    "name": "Product",
    "type": "object",
    "properties": {
        "product_name": {
            "type": "string",
            "minLength": 3
        "barcode": {
            "type": "string",
            "minLength": 12
        "description": {
            "type": "string",
            "minLength": 12
    "required": [


You can check that your generated schema is valid by using