elefcode

JSON → TypeScript, Zod & more

Turn sample JSON into TypeScript types, a Zod schema, JSON Schema, Go structs, Pydantic models, Rust serde structs or C# classes. Paste several samples to merge them.

JSON
export interface User {
  id: number;
  name: string;
  /** email */
  email: string;
  role: string;
  active: boolean;
  /** ISO 8601 date-time */
  createdAt: string;
  address: Address;
  tags: string[];
  manager: null;
}

export interface Address {
  street: string;
  city: string;
  zip: string;
}
Copy one:

2 types inferred. Keys missing from some samples are optional; keys that are sometimes null are nullable; objects with the same shape share a type.

Advertisement

Guide

About the JSON to TypeScript Generator

When you consume an API, you usually have an example JSON response but no matching types. Writing TypeScript interfaces by hand is tedious and error-prone, especially for deeply nested payloads. This tool reads any JSON object and generates ready-to-use TypeScript interfaces that describe its shape — nested objects become their own interfaces, arrays are typed by their elements, and mixed values are inferred as unions.

Paste a sample response and get types you can drop straight into your codebase, giving you autocomplete and compile-time safety with none of the manual typing. Everything is processed locally.

How the shape is inferred

The generator walks your JSON and infers a type for every field: strings, numbers, and booleans map directly; nested objects are extracted into their own named interfaces; and arrays are typed by inspecting their elements. Because inference is based on a single example, it's a strong starting point — but you should still review fields that can be null, optional, or vary between responses.

Tips for better types

Feed the tool the most complete example you have — one where optional fields are present — so nothing is missed. After generating, mark fields that may be absent with ?, and widen types where the API can return more than the sample shows (for example a status string that could be one of several values). A representative sample yields interfaces you'll barely need to touch.

How to use it

  1. 1Paste a JSON object or API response into the input.
  2. 2The matching TypeScript interfaces are generated instantly.
  3. 3Rename the root interface to something meaningful for your domain.
  4. 4Copy the interfaces into your project and refine optional or union fields as needed.

Frequently asked questions

Does this handle nested objects and arrays?

Yes. Nested objects are extracted into their own interfaces and arrays are typed by their element type, so complex, deeply nested JSON is fully supported.

Will it detect optional fields?

Yes, if you give it more than one example. Paste an array of objects, or JSON Lines (one object per line): a key missing from some of them becomes optional, and the types of all the samples are merged.

Can it generate types instead of interfaces?

Yes. Switch between interface and type, choose whether to export them, make properties readonly, and pick key?: or | undefined for optional properties.

Can I get a Zod schema or Go/Python/Rust types?

Yes. The same inferred model is written as a Zod schema (with z.infer types), JSON Schema 2020-12, Go structs with json tags, Pydantic v2 models, Rust structs with serde attributes, or C# classes for System.Text.Json.

Is my JSON uploaded to a server?

No. Parsing and type generation run entirely in your browser, so even private API responses stay on your device.

What about fields that are sometimes null?

Give it samples where the field is null and where it is not, and it becomes nullable (string | null, .nullable(), Option<String>, *string …). A field that is null in every sample has no other type to go on, so it is typed as null.

Learn more

Related tools