Tech

JSON to TypeScript converter

Paste JSON and we generate the TypeScript interfaces: it infers types, creates a separate interface for every nested object, and handles arrays. Everything runs in your browser.

Instant🔒In your browserNo signup
Live

Why generate types from JSON

When you consume an API or load a config file, the JSON arrives untyped: to TypeScript it is just a generic object. Writing the interfaces that describe that shape by hand is tedious and error-prone, especially with nested objects and arrays. Generating them automatically gives you autocompletion, type checking, and living documentation of the data structure, without typing out every single field.

How types are inferred

The tool walks the JSON and, for each value, picks the most specific TypeScript type it can: text becomes string, numbers number, booleans boolean, and null stays as null. Each nested object becomes its own interface with a PascalCase name derived from the key, and arrays are typed by looking at their first element: an array of strings is string[], an array of objects is ObjectName[].

Optional versus required fields

A sample JSON has all of its fields present, so the tool generates them as required. But in the real world many APIs return fields that are sometimes missing. If you know a field can be absent, mark it optional by adding ? before the colon: phone?: string. Likewise, if a field can be null in addition to its type, write a union such as nickname: string | null.

Unions and mixed types

Arrays are not always homogeneous. If an array mixes numbers and strings, generating number[] would be wrong. In that case the tool builds a union that reflects every type present, for example (number | string)[]. For an empty array there is nothing to infer from, so any[] is used and it is up to you to refine it. Unions are also handy by hand when the same field can hold values of different types.

Limits of inference

Inferring types from a single example has clear boundaries. The tool cannot know that a number is really an enum of three values, that a string follows an ISO date format, or tell a tuple apart from a regular array. It also cannot detect optional fields if your example always includes them. Treat the result as a solid starting point and refine it: rename generic interfaces, add optionals, and replace any where you have more context than the example provides.

Reference: JSON value to TypeScript type

Value in the JSONTypeScript type
"text"string
42 / 3.14number
true / falseboolean
nullnull
{ ... }named interface (PascalCase)
["x","y"]string[]
[]any[]
[1,"a"](number | string)[]

FAQ

How do I generate TypeScript interfaces from JSON?

Paste the JSON, name the root interface, and click "Generate interfaces". Each field type is inferred and a separate interface is built for every nested object.

Which types does it infer?

string, number, boolean, and null. Nested objects become named interfaces and arrays become an element type with brackets, like string[].

How does it handle empty arrays?

An empty array is typed as any[]. With items it uses the first one's type, and if they are mixed it generates a union such as (string | number)[].

What happens if my JSON is invalid?

It uses JSON.parse and, if that fails, shows a clear error message with the details instead of crashing.

Are fields optional or required?

All are required because the example contains them. If a field can be missing, add ? by hand: email?: string.

How are nested interfaces named?

From the key that holds them, in PascalCase: "address" produces Address. Duplicates are numbered to avoid collisions.

Is my JSON sent to a server?

No. Everything is processed in your browser; your JSON never leaves your device.

Can I copy the result?

Yes, the "Copy TypeScript" button copies all generated interfaces, ready to paste into your .ts file.

Was this generator useful?