How to generate types from JSON
- Paste some JSON into the JSON box, open a .json file, or choose Load example.
- Choose an output: TypeScript types, a Zod schema, or a JSON Schema.
- Optionally rename the top-level type, which is called
Rootto start with. - Copy the result into your project, or download it as a file.
The more examples you give it, the better the types. For an API that returns a list, paste several items rather than one, so fields that are sometimes missing or null are typed correctly.
How the types are worked out
- Objects in a list are merged. If some items have a key that others lack, it becomes optional (
coupon?: string). nulljoins the type as a union, such asstring | null. A field that is only evernullis typednull.- Lists with mixed values get a union element type, such as
(string | number)[]. Empty lists becomeunknown[], and empty objectsRecord<string, unknown>. - Nested objects get their own named type, made from the key in PascalCase:
billing_addressbecomesBillingAddress. Items in a list take the singular:usersgivesUserandcategoriesgivesCategory. Words that are already singular, such asdata, stay as they are. - Identical shapes share one type. If
homeandworkboth hold the same address fields, both use oneHometype. Different shapes that want the same name are numbered:Item,Item2. - A list at the top level becomes an alias, such as
type Root = RootItem[], ortype Users = User[]if you name itUsers. - Keys that are not valid identifiers, such as
"gift-wrap", are quoted. - Names that would hide a built-in type, such as
DateorMap, getTypeadded:DateType.
The three outputs
| Output | Use it for | Options |
|---|---|---|
| TypeScript | Describing data in your code. Types are checked when you compile, not when the data arrives. | interface or type, export, readonly |
| Zod | Checking data at run time, for example an API response, and getting the TypeScript type from the same schema with z.infer. | export, string formats |
| JSON Schema | Validating data in any language, documenting an API, or configuring tools that accept a schema. Uses draft 2020-12. | String formats |
Check string formats recognises values that are all dates (2026-10-25), date-times with a time zone (2026-10-25T09:30:00Z), email addresses, URLs or UUIDs, and adds a check for them. If any value at that position does not match, the plain string type is used. Only the JSON Schema output tells whole numbers (integer) apart from other numbers.
Limitations
- The types describe only the sample you paste. A field that can hold other values in real data, or a key that appears only in rare cases, is missing until it is in the sample.
- Objects whose keys are IDs or names, such as
{"u_123": {…}, "u_456": {…}}, become a type with one property per key. The tool warns when an object has more than 100 keys; a map type such asRecord<string, User>usually suits them better. - Values are not turned into literal or enum types:
"status": "active"is typedstring, not"active". - Input is limited to 5 million characters and 100 levels of nesting. Comments and trailing commas (JSON5, JSONC) are not accepted.
Frequently asked questions
Is my JSON uploaded?
No. The types are worked out by JavaScript running on this page, in your browser. That matters when the JSON is a real API response containing customer records, tokens or internal IDs: none of it leaves your device.
Why is a field typed as <code>null</code>?
In your sample that field was always null, so there was nothing else to go on. Paste more examples, such as several records from the same API, and any other type seen for it is added, for example string | null. You can also edit the result by hand.
Why are dates typed as strings rather than <code>Date</code>?
Because that is what they are. JSON has no date type, so JSON.parse and fetch().json() give you strings such as "2026-10-25T09:30:00Z". Typing them as Date would be wrong until your code converts them. The Zod and JSON Schema outputs can check the format of those strings for you.
Which version of Zod does the schema need?
Zod 3.23 or later, including Zod 4. It uses long-standing methods such as z.string().email() and z.string().datetime(), which Zod 4 still supports.
