PB
Available
code
lock Free · Private · In-Browser

JSON to PHP Class

Draft strict PHP value objects from a representative JSON payload.

 

Turn JSON records into PHP value objects

Modern PHP can model API payloads with typed constructor promotion instead of arrays passed throughout an application. This generator parses a JSON object and writes final classes with public readonly constructor properties. Whole numbers use int, decimal values use float, booleans use bool, strings use string, arrays use array, and nested objects receive their own named class.

For the default JSON, the User constructor accepts readonly int userId, readonly string name, and readonly bool active. A nested address object generates an Address class and uses that class as the parent property type. The output includes strict_types so it can serve as a clean starting point for DTOs, command objects, or decoded API responses.

Type inference without framework assumptions

The generator does not invent serializer annotations or hydration code because Symfony, Laravel, and standalone projects use different conventions. Null and mixed structures require manual union or nullable types, while snake-case wire keys may need a mapper. Your payload is parsed in your browser only. Add factory methods or serializer metadata that matches the library already used by your application.

Frequently Asked Questions

Which PHP version does the generated style assume?

Readonly promoted constructor properties require a modern PHP release; adjust the syntax for older runtimes.

Does this generate array hydration code?

No. It creates typed value-object classes so you can connect them to your preferred serializer or factory.

Are nested objects supported?

Yes. Each nested object becomes another final class and is used as the parent property type.

Take it further
All Free Tools

Browse the full set of free, private, in-browser tools.

Learn More arrow_forward