Paste JSON and get TypeScript interfaces or typed PHP classes in one click.
Paste any JSON. Get TypeScript interfaces or PHP classes with the right types, nested objects, and optional fields.
1.5 or 2.0 becomes float in PHP. A whole number becomes int. TypeScript uses number for both.null in some items becomes nullable.string | number. PHP 8.0 and newer use a union type. PHP 7.4 has none, so the type is left out and a comment explains it.unknown[] in TypeScript and array in PHP.orders gives an Order type for each item.Decode your JSON as an array, then build the object:
$data = json_decode($json, true); $user = Root::fromArray($data); echo $user->name;
If the top level of your JSON is a list, map each item: array_map(fn($row) => Item::fromArray($row), $data).
Types come from the example you paste, so the tool can only describe what it sees. A field that is always present in your sample may be optional in the real API. A number that is a whole number in your sample may be a decimal later. Use a sample with several items, or paste more than one, to get a more reliable result. Review the output before you rely on it.
Paste the JSON into the box on the left and choose TypeScript. The interface appears on the right. Nested objects become their own interfaces, and lists become arrays such as string[].
Yes. Copy the response body from your browser’s network tab, Postman or curl and paste it in. If the response is a list, the tool builds a type for one item and a type for the list.
When your JSON has a list of objects, a field that is missing from some of them is marked optional (name?: string in TypeScript, nullable with a default of null in PHP). A field that is present but set to null becomes string | null.
PHP 7.4 uses typed properties. PHP 8.0 adds constructor promotion and union types. PHP 8.1 and newer can mark properties readonly. Pick the one that matches your server.
The sample had no value to learn from (an empty list or only null), or the field holds several kinds of values and your PHP version has no union types. The docblock above the property shows the intended type.
TypeScript quotes them: "user-name": string. PHP turns them into a valid property name such as $userName, and fromArray() and toArray() still use the original key.
No. The code is generated in your browser. Your JSON never leaves your device, and the tool is free with no sign-up.