JSON to PHP Class

Generate PHP classes from JSON

About JSON to PHP Class

JSON to PHP Class generates a class definition with one typed property per top-level JSON key — not a PHP array or object populated with your actual data — entirely in your browser. It uses PHP 7.4+ typed property syntax (e.g. public float $age;), so the output requires PHP 7.4 or later and is not compatible with PHP 5.4 as sometimes assumed.

How to use JSON to PHP Class

  1. 1Paste your JSON into the input box.
  2. 2Click 'Convert' to generate a PHP class with typed properties.
  3. 3Review the output — this defines the shape of your data, not a filled-in array.
  4. 4Click 'Copy' to copy the code into your project.

Frequently Asked Questions

Is JSON to PHP Class free to use?

Yes, it's completely free with no signup required.

Does it generate a PHP array or object containing my actual JSON data?

No — it generates a class definition with typed property declarations, such as public string $name;, not a populated array like ['name' => 'John'].

What PHP version does the generated code require?

PHP 7.4 or later, since it uses typed property syntax. It will not work on PHP 5.4 through 7.3.

Does it handle nested JSON objects?

No — only top-level keys become typed properties; nested objects are typed as mixed and arrays as array, without generating separate nested classes.

Tips & Tricks

  • If you need your actual JSON values as a PHP array, use PHP's own json_decode($json, true) instead — this tool only generates a class shape, not populated data.
  • For nested objects, manually create additional classes and update the generated property types to reference them.
  • Typed properties require PHP 7.4+; avoid them or add compatibility handling if you must support older PHP.
  • Property names are used exactly as written in your JSON, without case conversion — rename them by hand if you want camelCase.