wwwision/jsonschema

PHP Classes to represent JSON schema, see https://json-schema.org/

Maintainers

👁 bwaidelich

Package info

github.com/bwaidelich/jsonschema

pkg:composer/wwwision/jsonschema

Fund package maintenance!

bwaidelich

Paypal

Statistics

Installs: 7 729

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.1 2025-06-17 09:50 UTC

Requires

Requires (Dev)

Suggests

Provides

None

Conflicts

None

Replaces

None

MIT 0c8dbaebf88655ad2badbc1bf26703b0da1871d2

  • bwaidelich <b.waidelich.woop@wwwision.de>

This package is auto-updated.

Last update: 2026-06-17 11:52:32 UTC


README

PHP Classes to represent JSON Schemas, see JSON Schema

Usage

This package can be installed via composer:

composer require wwwision/jsonschema

With that, you can define a JSON Schema in PHP:

$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);

JSON Schema generator

See wwwision/types-jsonschema package for a JSON Schema generator that can generate JSON Schemas from PHP classes.

Contribution

Contributions in the form of issues or pull requests are highly appreciated

License

See LICENSE