JSON to TypeScript, Zod and JSON Schema

Turn JSON into TypeScript types, a Zod schema or a JSON Schema.

Runs in your browser. Your input is not uploaded.

Output
Declare types with

Paste JSON, open a .json file or drop one here. The result updates as you type.

Types
0
Lines
0

How to generate types from JSON

  1. Paste some JSON into the JSON box, open a .json file, or choose Load example.
  2. Choose an output: TypeScript types, a Zod schema, or a JSON Schema.
  3. Optionally rename the top-level type, which is called Root to start with.
  4. 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).
  • null joins the type as a union, such as string | null. A field that is only ever null is typed null.
  • Lists with mixed values get a union element type, such as (string | number)[]. Empty lists become unknown[], and empty objects Record<string, unknown>.
  • Nested objects get their own named type, made from the key in PascalCase: billing_addressbecomes BillingAddress. Items in a list take the singular: users gives User andcategories gives Category. Words that are already singular, such as data, stay as they are.
  • Identical shapes share one type. If home and work both hold the same address fields, both use one Home type. 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[], or type Users = User[] if you name it Users.
  • Keys that are not valid identifiers, such as "gift-wrap", are quoted.
  • Names that would hide a built-in type, such as Date or Map, get Type added: DateType.

The three outputs

OutputUse it forOptions
TypeScriptDescribing data in your code. Types are checked when you compile, not when the data arrives.interface or type, export, readonly
ZodChecking 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 SchemaValidating 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 typed string, 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.