{ }jsonkit
Format
Validate
Convert
Query
Generate
→php

JSON to PHP Class Generator

Create typed PHP 8 DTO models and JSON key maps.
353 B · paste or drop a file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
✓ complete353 B → 1141 B0.0 ms

About JSON to PHP

The JSON to PHP generator creates typed PHP 8 data-transfer classes from an example document. Nested objects become final classes, scalar values receive native property types, arrays receive list docblocks for PHPStan or Psalm, and missing or null values become nullable constructor parameters.

Generated models use constructor property promotion to stay compact. Readonly mode targets immutable DTOs, while the optional JSON key map records how sanitized camelCase property names correspond to keys such as order_id or created-at for use in your own hydrator or serializer.

Conversion is performed locally in the current browser tab, so internal API responses and personal data remain on your device. PHP does not provide automatic JSON-to-object hydration from type declarations alone; connect the generated classes to your serializer, framework normalizer or explicit factory method.

How it works

Infer native PHP 8 property types

JSON strings become string, booleans become bool, whole numbers become int and decimals become float. Nested objects receive their own classes. Null values and keys missing from some sampled object-array elements become nullable promoted properties.

Describe array element types

PHP's runtime array type cannot express its element type, so generated constructors use array plus a list<T> docblock. Static analyzers and IDEs can then understand lists of scalar values or nested model objects.

Use readonly DTO classes

Readonly mode emits final readonly classes for immutable transfer objects and requires PHP 8.2 or newer. Turn it off for PHP 8.0 or 8.1, or whenever properties must be changed after construction.

Preserve original JSON key names

PHP property names are sanitized to safe camelCase identifiers. The JSON key map method returns original-key to property-name pairs that a custom hydrator can consult. It is metadata, not an automatic deserializer.

Frequently asked questions

Which PHP version does the generated code require?

Constructor property promotion requires PHP 8.0. The readonly class option requires PHP 8.2; disable it for PHP 8.0 or 8.1. Strict types and union-free nullable property syntax are otherwise standard PHP 8 features.

Will json_decode return these classes automatically?

No. json_decode returns arrays or stdClass objects. Use a framework serializer, a reflection-based hydrator or a factory that constructs the generated classes. The optional key map can help translate wire names.

Why are arrays documented with list types?

PHP only enforces array at runtime. list<T> docblocks preserve the inferred element type for PHPStan, Psalm and IDE completion without pretending PHP can enforce generic arrays natively.

Does the PHP generator send JSON anywhere?

No. Parsing, inference and PHP source rendering all happen locally in the browser, so your input is not uploaded.