JSON to PHP class
Turn a JSON sample into a typed PHP class with a constructor, fromArray and toArray.
JSON to PHP class
Paste a JSON object or array and this tool infers a type for every field, then generates a ready-to-use PHP class: typed properties, a constructor, a static fromArray() factory and a toArray() method for turning the object back into a plain array. Nested objects become their own classes automatically, and identical shapes are reused instead of duplicated, so a payload with several similarly-structured sections still produces a compact file.
Class name and namespace name the root class and, optionally, wrap it in a PHP namespace. PHP 8 promoted constructor writes properties directly in the constructor signature instead of declaring them separately — turn it off for a classic explicit constructor. Generate getters and setters adds accessor methods (isX() for booleans, getX()/setX() otherwise) instead of exposing properties directly. declare(strict_types=1) adds PHP's strict type header, and docblock comments annotate every property with its inferred type. Array fields decides whether a list is typed as a plain array or documented with its element type, such as string[], since PHP has no generics for that in the type hint.
A field seen as null, or missing from some elements of an array of objects, is generated as nullable — with a safe isset() check when it needs to build a nested object or map a list, and a null-coalescing default otherwise. A key that collides with a PHP keyword or starts with a digit is renamed to a valid property name, and every generated property keeps the original JSON key as its array key in fromArray() and toArray().
Everything runs locally in your browser — the JSON you paste, which may include real API responses or config data, is never uploaded anywhere. Copy the generated class, download it as a .txt file, or send the output back into the input to refine it further.