CodeMash

JSON to TypeScript Interface Generator

Generate TypeScript interfaces from JSON data. Supports nested objects and arrays.

Ad Space

Frequently Asked Questions

How do I generate TypeScript interfaces from JSON?

Paste your JSON data into the input box. Our tool automatically infers types and generates clean TypeScript interfaces, including nested objects and arrays.

How are nested objects handled?

Nested objects are extracted into separate named interfaces. Interface names are derived from property names in PascalCase (e.g., address becomes Address).

Does this support arrays and optional fields?

Yes, arrays are typed based on element types (e.g., number[] or string[]). Empty arrays are typed as unknown[]. All fields from the sample are generated as required.

Can I use this for API response types?

Absolutely. Paste an API response JSON and get ready-to-use TypeScript interfaces for your frontend application.

Privacy First: All processing happens directly in your browser. Your data never leaves your device.

About JSON → TypeScript

Generating interfaces from a JSON sample gives you a typed starting point in seconds. The types are inferred from one example, though, and that limitation is worth understanding before you commit the output to your codebase.

What gets inferred

Each object becomes an interface, nested objects become their own named interfaces, and arrays are typed from their first element. Primitives map to string, number and boolean.

A sample and its generated interfaces
{ "id": 1, "name": "Alice", "tags": ["admin"], "address": { "city": "Berlin" } }

interface Address {
  city: string;
}

interface Root {
  id: number;
  name: string;
  tags: string[];
  address: Address;
}

Where inference from a single sample falls short

  • A field that is null in your sample carries no type information — null alone cannot tell you whether the field is a nullable string or a nullable object.
  • Optional fields are invisible. A key absent from the sample simply does not appear, so the generated type asserts that every field is always present.
  • A heterogeneous array types from its first element only; a genuine union is silently narrowed.
  • Numeric strings, dates and enums all arrive as string. An ISO timestamp is indistinguishable from any other string at the JSON level.
  • Integers and floats are both number, since JavaScript makes no distinction.

Treat the output as a first draft

The generated interfaces are a scaffold that removes the tedious part, not a schema. Before using them, mark genuinely optional fields as optional, widen fields that can be null, replace fixed string sets with union types, and rename the root interface to something meaningful.

If you control the API, generating types from its OpenAPI or JSON Schema definition instead will give you all of the above correctly — inference from a payload is the right tool only when no schema exists.