JSON to TypeScript, PHP & Go Types
Paste a JSON sample and get matching type declarations: TypeScript interfaces, PHP 8.2 readonly classes with promoted properties, or Go structs with json tags.
Runs in your browser — nothing is uploaded.
How to use it
- Paste a representative JSON sample. The more varied the items in your arrays, the better the result.
- Pick TypeScript, PHP or Go, and set the name of the root type.
- Arrays of objects are merged into one type: a field missing from some items becomes optional, and a null becomes a nullable type.
- Copy the code or download it, then adjust names and types by hand where the sample could not tell enough.
Frequently asked questions
Is my JSON uploaded?
No. The types are generated in your browser and nothing is sent anywhere.
How are optional and nullable fields detected?
From the sample. If a key is missing in some objects of an array it is optional (? in TypeScript, = null in PHP, a pointer with omitempty in Go). If a value is null in the sample, the type includes null.
Why do I get any, mixed or unknown?
The sample did not say enough: an empty array has no element type, a lone null has no other type, and values of different types in the same position cannot be expressed as one type in Go.
Which PHP version do the classes need?
PHP 8.2 or newer, because they are final readonly classes with constructor property promotion. Arrays are typed with PHPDoc such as @param Item[] $items.
Are integers and decimals told apart?
Yes. 1 is an integer (int, int64) and 1.5 a float (float, float64). If both appear for the same key the field becomes a float. In TypeScript both are number.