JSON to TypeScript

Interfaces, types and Zod schemas

No database: AIMRAN doesn't store your files, text or results

What is JSON to TypeScript?

If you work with TypeScript and get JSON data from an API, writing the types by hand is slow. This tool reads a JSON sample and automatically generates the interfaces or types that describe it.

It can also generate a Zod schema to validate that data at runtime, with the inferred type ready to use.

How to use it

  1. Paste your JSON or load the example.
  2. Choose the output: TypeScript or Zod schema.
  3. Select whether to declare it as an interface or a type.
  4. Enter the root type name and turn on “Add export” if you need it.
  5. Copy or download the generated code.

Advantages

Technical details

The tool infers a structural type from the JSON value: string, number, boolean, null, objects and arrays. In arrays, the types of all items are unified; if they're objects, their fields are merged and keys missing from any item are marked optional (?), and if types differ a union is generated. Each nested object produces a declaration named after its key. Empty arrays are typed as unknown[]. In Zod mode, z.object, z.array, z.union and .optional() are generated, and type Name = z.infer<typeof NameSchema> is added. Keys that aren't valid identifiers are quoted.

Frequently asked questions

How do I convert JSON to a TypeScript interface?

Paste the JSON, choose TypeScript and “interface”, and copy the result. Each nested object gets its own interface.

What's the difference between interface and type?

For describing objects they're almost equivalent. Interfaces can be extended and merged; types allow unions and more complex types.

What is Zod?

A TypeScript library for validating data at runtime. The schema checks that data has the expected shape and the type is inferred from it.

How does it detect optional fields?

In arrays of objects, if a key is missing from any of the items, it's marked as optional.

Does it detect dates in the JSON?

No. JSON has no date type, so dates are generated as string.

More Developers tools