PHPackages                             tomasz-kusy/annotations-to-json-schema - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. tomasz-kusy/annotations-to-json-schema

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

tomasz-kusy/annotations-to-json-schema
======================================

Convert Symfony validator annotations to json schema

08PHP

Since Dec 29Pushed 5y ago1 watchersCompare

[ Source](https://github.com/tomasz-kusy/annotations-to-json-schema)[ Packagist](https://packagist.org/packages/tomasz-kusy/annotations-to-json-schema)[ RSS](/packages/tomasz-kusy-annotations-to-json-schema/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

annotations-to-json-schema
==========================

[](#annotations-to-json-schema)

Generate JSON Schema documents based on annotations in PHP files.

Version at developer stage.

Motivation
----------

[](#motivation)

Many people (e.g. me) use PHP to transfer objects between client and server (DTO). The object must be serialized (ex. to XML or JSON) before it can be sent. After receiving such an object, the server performs a deserialization. For this it needs to know how to perform the conversion. If the client and the server use the same metadata, there is usually no problem. Worse if the structure of the serialized data does not match the server's metadata, e.g. you will get a string instead of the expected array of objects. In this case, the deserializer will report an exception and stop further processing. The most popular serializers (Symfony, JMS) will return very brief information about the cause of the problem.

Solution
--------

[](#solution)

The solution may be to validate the JSON document before it goes to deserialization. To validate documents we can use JSON Schema documents. This package allows to create JSON Schema documents based on existing PHP entities.

Usage
-----

[](#usage)

Base entities should utilize PSR-4 compatible paths.

TO BE CONTINUED...

#### Standalone

[](#standalone)

```
Usage:
  convert2jschema [options] [--]

Arguments:
  className                                  Entry class

Options:
  -c, --config[=CONFIG]                      Config file
  -r, --root-namespace[=ROOT-NAMESPACE]      RootNamespace
  -o, --destination-path[=DESTINATION-PATH]  Output directory
```

Sample `config.yaml`:

```
# config.yml

a2jschema:
  rootNamespace: TKusy\JSchema\Tests\Assets\
  idPrefix: http://json-schema.org/schema/

  destination:
    path: ~
    pathTemplate: "%s.schema.json"
```

#### Samples

[](#samples)

`bin/convert2jschema -c config.yaml TKusy\\JSchema\\Tests\\Assets\\Main\\Referral` - use config yaml to generate schemas as 'siblings' of entities.

`bin/convert2jschema --root-namespace=TKusy\\JSchema\\Tests\\Assets\\ --destination-path=./output/ Main\\Referral` - write schemas to `./output` dir.

#### In PHP

[](#in-php)

@TO DO...

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity31

Early-stage or recently created project

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/a189b7f3f5ada446af477e5edb60083200353e8e7709e7813df137d673c25445?d=identicon)[tomasz-kusy](/maintainers/tomasz-kusy)

### Embed Badge

![Health badge](/badges/tomasz-kusy-annotations-to-json-schema/health.svg)

```
[![Health](https://phpackages.com/badges/tomasz-kusy-annotations-to-json-schema/health.svg)](https://phpackages.com/packages/tomasz-kusy-annotations-to-json-schema)
```

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)

PHPackages © 2026

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