A PHP project that serializes and deserializes DTOs often needs a JSON Schema for them — for an LLM's structured output, for API documentation, or to validate incoming payloads.
Writing it by hand works until the code changes. With Symfony Serializer, the JSON shape can shift without the PHP types changing at all — a new serialization group, a #[SerializedName], a discriminator — and the hand-written schema no longer matches what the serializer produces.
json-schema-extractor is a PHP library that generates JSON Schema from DTOs by reading the metadata they already carry — native types, PHPDoc, and serializer configuration — so the schema stays in sync with the code. It supports plain json_encode/JsonSerializable and Symfony Serializer; this article focuses on the latter.
The problem in concrete terms
Take a simple DTO:






