JSON to Language Struct / Class Generator
About JSON → PHP Class
The JSON to PHP 8+ Class & DTO Generator converts JSON payloads into modern PHP 8.2+ readonly classes with constructor property promotion, Spatie Laravel Data objects, and typed getters/setters.
How to Use JSON → PHP Class
Step 1
Paste your JSON payload into the input pane.
Step 2
Select PHP version target (PHP 8.2 Readonly, Laravel DTO, or Classic PHP).
Step 3
Specify root class name (e.g. `PostDto`).
Step 4
Click "Copy PHP Code".
Practical Use Cases for JSON → PHP Class
Laravel & Symfony DTO (Data Transfer Object) Generation
Convert API request JSON payloads into typed PHP 8 DTO classes with constructor property promotion and `fromArray()` methods.
WordPress & Legacy PHP POPO Integration
Generate standard PHP classes with getter/setter methods and JSON serialization interfaces (`JsonSerializable`).
Input & Output Examples
Converting JSON to PHP 8.2 Readonly Class
`{ "id": 1, "title": "Post", "published": true }``readonly class Post {\n public function __construct(\n public int $id,\n public string $title,\n public bool $published,\n ) {}\n}`Key Features & Performance
- ✓Outputs: PHP 8.2 `readonly class`, Spatie Laravel Data DTO, Standard POPO with Getters/Setters, or `JsonSerializable`.
- ✓PHP 8 Constructor Property Promotion minimizes boilerplate.
- ✓Auto-converts snake_case keys to camelCase properties with mapping arrays.
- ✓100% Client-Side memory execution.
- ✓1-Click Copy PHP code.
Key Terminology & Definitions
Constructor Property Promotion
A PHP 8 feature allowing class properties and constructor arguments to be declared simultaneously in the constructor signature.
Readonly Class (PHP 8.2)
A class where all declared properties are implicitly marked as readonly and cannot be modified after initialization.
