JSON to PHP
PHP 8 classes with typed properties and a fromArray factory.
About this tool
Paste JSON and get PHP 8 data transfer objects. Choose readonly properties (PHP 8.1+) and final classes, add a namespace, and copy the code into your project.
How the PHP is generated
Each JSON object becomes a class with typed, constructor-promoted properties and a static fromArray() factory that works with json_decode($json, true). Keys become camelCase properties (user_name โ $userName) while fromArray reads the original keys. Nested objects are built with ::fromArray, lists of objects are mapped with array_map, and PHPDoc tells IDEs and static analysers what arrays contain (string[], Order[]). Array items are merged before types are chosen, so a key that only some items have, or that is sometimes null, is treated as optional or nullable rather than breaking decoding. Those become nullable (?string), and optional ones move to the end of the constructor with a null default. Decimals are cast to float, so whole-number JSON values don't break strict types. Honest limits: types describe your sample, and always-null values become mixed. JSON to C#, JSON to TypeScript and the JSON formatter are related.
Frequently asked questions
How do I convert JSON to a PHP class?
Paste the JSON here, copy the classes, then call User::fromArray(json_decode($json, true)).
Which PHP version is needed?
PHP 8.0 for promoted properties and named arguments, and 8.1 for readonly properties.
Why cast to float?
JSON numbers like 12 decode as int in PHP. The cast keeps float properties valid under strict types.
Is my JSON uploaded?
No. Everything runs in your browser and nothing is stored or sent.