JSON to PHP Class

Generate PHP 8 classes with typed constructor property promotion from JSON. Each class becomes a value object you can hydrate from json_decode output. Drop into Laravel / Symfony / any PHP 8.1+ codebase.

How to use the JSON to PHP Class

Paste JSON. Output uses PHP 8 constructor promotion — fewer lines than the old getter/setter style. For PHP <8.0, expand into traditional property declarations + constructor body.

Generating PHP classes from JSON

Working with a decoded JSON array in PHP means string keys everywhere and no type safety — one typo in a key like $data['emial'] and you find out at runtime. Typed value objects fix that, but defining a class per object with proper property types is exactly the boilerplate PHP 8 was meant to cut down.

This generates PHP 8 classes with typed constructor property promotion from a JSON sample, so each object becomes a compact value object you can hydrate from json_decode output and drop straight into a Laravel, Symfony, or any PHP 8.1+ codebase. Nested objects become their own classes. For PHP versions before 8.0, expand the promoted constructor into traditional property declarations.

Common use cases

  • Typed value objects — replace associative arrays with typed classes.
  • Constructor promotion — get compact PHP 8 classes, not getter/setter boilerplate.
  • Hydrate responses — build objects from json_decode output.
  • Framework ready — drop into Laravel, Symfony, or plain PHP 8.1+.
  • Nested classes — generate a class for each nested object.

Frequently asked questions

Which PHP version does it target?

PHP 8 with typed constructor property promotion; it works in any PHP 8.1+ codebase.

How do I use it with older PHP?

For PHP before 8.0, expand the promoted constructor into traditional property declarations plus a constructor body.

How do I populate the objects?

Hydrate them from json_decode output, passing the decoded values into the constructor.

Are nested objects supported?

Yes — each nested object becomes its own typed class.
Embed this tool on your site

Free to embed, no attribution required (but appreciated). Paste this where you want the tool to appear: