JSON to PHP Class Generator

Paste JSON, get PHP code instantly. Private, in your browser.

Input

Output

Ready
Ln 1, Col 1

Convert JSON to PHP in one step

Paste JSON and get PHP 8.1+ data transfer objects with constructor-promoted readonly properties and a fromArray() factory that builds nested objects.

How to use it

  1. Paste a JSON sample into the Input panel, open a file, or drop it onto the page. A sample is already loaded so you can see the result.
  2. The PHP code appears instantly in the Output panel and updates as you type.
  3. Rename the top-level type under Settings → Root type name, and use Sort keys to order fields alphabetically.
  4. Copy the code or Download it as Root.php.

What the PHP generator produces

  • final classes with typed, readonly promoted properties.
  • fromArray() maps the original keys and builds nested objects and lists of objects.
  • Nullable types (?int) for optional or null values; @var docblocks describe array item types.
  • declare(strict_types=1) and camelCase property names.

Using the generated PHP code

Decode JSON and build the objects:

$data = Root::fromArray(json_decode($json, true, flags: JSON_THROW_ON_ERROR));
echo $data->users[0]->name;

More JSON tools

All tools are free and run privately in your browser.

JSON to PHP FAQ

Which PHP version is required?

PHP 8.1 or newer, for readonly properties. For PHP 8.0, remove the readonly keyword.

Is my data uploaded to a server?

No. The JSON to PHP runs entirely in your browser using JavaScript. Your data is never uploaded, logged or stored, and the tool keeps working offline after your first visit.