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
- Paste your JSON or load the example.
- Choose the output: TypeScript or Zod schema.
- Select whether to declare it as an interface or a type.
- Enter the root type name and turn on “Add export” if you need it.
- Copy or download the generated code.
Advantages
- Generates interfaces, types or Zod schemas.
- Nested objects get their own named types.
- Merges array items and marks missing keys as optional.
- Free, no sign-up and no ads.
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
- Base64, URL and HTML · Encode and decode in all three formats
- Hash generator · MD5 and SHA for text or files
- UUID generator · Unique identifiers instantly
- Strong passwords · With a strength meter
- JWT decoder · Read header, payload and expiry
- Regex tester · Highlighted matches and groups
- Colours and gradients · HEX, RGB, HSL, OKLCH, contrast and gradients
- CSS shadows · box-shadow with live preview