1. Go to this page and download the library: Download wwwision/jsonschema library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
wwwision / jsonschema example snippets
$schema = new ObjectSchema(
title: 'Product',
description: 'A product in the catalog',
properties: ObjectProperties::create(
id: new StringSchema(
title: 'ID',
description: 'The unique identifier for a product',
format: StringFormat::uuid,
),
title: new StringSchema(
title: 'Product title',
description: 'The name of the product',
),
available: new BooleanSchema(
title: 'Whether the product is available',
),
price: new NumberSchema(
title: 'Price',
description: 'The price of the product',
default: 0.0,
minimum: 0.0,
)
)
);
$expected = <<<JSON
{
"type": "object",
"title": "Product",
"description": "A product in the catalog",
"properties": {
"id": {
"type": "string",
"title": "ID",
"description": "The unique identifier for a product",
"format": "uuid"
},
"title": {
"type": "string",
"title": "Product title",
"description": "The name of the product"
},
"available": {
"type": "boolean",
"title": "Whether the product is available"
},
"price": {
"type": "number",
"title": "Price",
"description": "The price of the product",
"default": 0,
"minimum": 0
}
}
}
JSON;
assert(json_encode($schema, JSON_PRETTY_PRINT) === $expected);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.