Code Generators · Runs in your browser

JSON to PHP Class Generator

Paste a JSON sample and get ready-to-use PHP classes, with nested types, arrays and optional fields worked out for you. Ideal for turning json_decode output into typed objects in Laravel or Symfony.

JSON
Drop a file to load it
PHP
Waiting for input

How to use it

  1. Paste a representative JSON sample, such as an API response.
  2. Set the root type name and pick a style: PHP 8.1 classes with readonly properties.
  3. Copy the PHP code or download it as a file.

fromArray()

Each class has a fromArray() constructor that maps the original keys and builds nested objects, so Root::fromArray(json_decode($json, true)) just works.

Typed properties

Constructor-promoted readonly properties with nullable types for optional fields.

Integers vs. decimals

Number types come from how the number is written in your sample: 3 is an integer, 3.0 and 3.5 are decimals, and long IDs use a 64-bit type.