Skip to content

DTO Playground ​

Paste JSON data and instantly see the generated DTO configuration. This helps you quickly bootstrap DTOs from API responses or existing data structures.

JSON Input
DTO Configuration
<?php

use PhpCollective\Dto\Config\Dto;
use PhpCollective\Dto\Config\Field;
use PhpCollective\Dto\Config\Schema;

return Schema::create()
    ->dto(Dto::create('Address')->fields(
        Field::string('street'),
        Field::string('city'),
        Field::string('zipCode'),
    ))
    ->dto(Dto::create('Metadata')->fields(
        Field::string('createdAt'),
        Field::bool('active'),
    ))
    ->dto(Dto::create('Object')->fields(
        Field::int('id'),
        Field::string('name'),
        Field::string('email'),
        Field::dto('address', 'Address'),
        Field::array('roles'),
        Field::dto('metadata', 'Metadata'),
    ))
    ->toArray();

This is a simplified preview. The actual Schema Importer supports JSON Schema, OpenAPI, and more advanced type inference.

How It Works ​

  1. Paste JSON — Any valid JSON object
  2. Choose format — PHP Builder, XML, or YAML
  3. Copy output — Use in your project

Tips ​

  • Nested objects become separate DTOs
  • Arrays of objects become collections
  • Field names are preserved as-is (the actual generator converts to camelCase)

For Production Use ​

This browser-based tool provides a quick preview. For full functionality including:

  • JSON Schema parsing with $ref resolution
  • OpenAPI document support
  • External file references
  • Type inference from multiple examples

Use the CLI importer:

bash
# From JSON data
php -r "echo (new PhpCollective\Dto\Importer\Importer())->import(file_get_contents('data.json'));"

# Or save to file
vendor/bin/dto import data.json --output=config/dto.php

See Schema Importer for complete documentation.

Released under the MIT License.