JSON to TypeScript interfaces

Paste a JSON sample and get TypeScript interfaces or type aliases for it, with nested types named for you and optional fields inferred from the data.

Paste JSON in first; its readable text, tables and types appear here.

How to generate TypeScript types

  1. Paste a real response or file in View & search (it accepts comments and trailing commas).
  2. Open Text, table & types and choose TypeScript.
  3. Set the root type name, choose interface or type, and readonly if you want it.
  4. Copy the code into your project.

What the generated types look like

Every object becomes its own named interface, lists become arrays of the right type, and values that are sometimes missing in a list become optional (qty?: number). Values that can be null get | null. When the root of your JSON is a list, the root type is an array of an item type, for example type Root = RootItem[].

Use a representative sample

Types are inferred from the sample you paste, so a field that never appears in the sample cannot appear in the types, and a field that is always present is required. Paste a response that includes the optional parts of the data, or several records in a list, and the result will match your API much more closely.

Tested before you see it

Type generation uses quicktype, an established open-source engine, running in a background worker in your browser. pastejson checks its own output in automated tests: the TypeScript generated for dozens of sample documents must compile with strict settings.

Questions

Interface or type alias?

Both work. Interfaces are common for object shapes; choose type if your codebase prefers aliases.

How are optional fields decided?

A field missing in some items of a list becomes optional. Fields present in every item are required.

Does it handle nested objects and arrays?

Yes. Nested objects get their own named types and arrays get the type of their items.

Is the JSON uploaded to generate types?

No. Generation runs in a worker inside your browser.

Can I also get a Zod schema?

Yes. Choose Zod in the same tab to get a schema and its inferred type.