Class name:
JSON Input 0 B
Ready
0 chars
PHP Output 0 B
PHP classes will appear here...
—
0 chars
Features

Why use this generator

Modern PHP

Uses typed properties (PHP 7.4+) and a static fromJson factory method. Compatible with PHP 7.4+ and 8.x.

Type mapping

JSON strings become string, integers become int, floats become float, booleans become bool, null becomes null. Arrays stay as array.

fromJson method

Each class includes a static fromJson(string $json): self method that decodes JSON and populates the object.

How it works

Conversion explained

1. Parse JSON

Input is parsed into a JavaScript value. The class structure is determined by walking the value tree.

2. Collect classes

For each object, a PHP class is generated with typed public properties and a fromJson factory.

3. Emit PHP

Classes are emitted with proper PHP formatting: <?php opening tag, typed properties, and a static factory method.

FAQ

JSON to PHP Class Generator — frequently asked questions

Which PHP version is required?

PHP 7.4+ for typed properties. For PHP 7.0-7.3, remove the type annotations. PHP 8.x is fully supported.

Is this compatible with Laravel?

Yes — the generated classes work as plain PHP objects. For Laravel Eloquent models, you'll need to add the Model base class, $fillable property, and table name.

How are nullable fields handled?

Currently, nullable fields use null as the type. Edit the output to use specific nullable types like ?string, ?int.

Why doesn't PHP have generics?

PHP doesn't support generics in the type system. Arrays are typed as array without specifying the value type. Use PHPDoc comments (@var User[]) for IDE autocompletion.