JSON to TypeScript Interface

JSON Tools

How to use the JSON to TypeScript Interface

Generate TypeScript interfaces in one step:

1

Paste your JSON

Paste a JSON object (or array of objects) into the input. The generator uses the structure and value types to infer TypeScript types.

2

Set the root interface name

Choose the name for the root interface (default: 'RootObject'). Nested objects get their own named interfaces automatically.

3

Click Generate

The TypeScript output appears with properly typed interfaces. Arrays become typed arrays (string[], number[], NestedType[]).

4

Copy into your project

Copy the generated interfaces directly into your .ts or .d.ts file. Review and refine — for example, marking optional fields with ?.

5

Refine the output

Types are inferred from sample values. Fields that could be null in real responses should be changed to string | null or T | undefined after generation.


When to use this tool

Stop writing TypeScript interfaces by hand. Use this tool when:

  • You receive a new API response and need to type it for your TypeScript project immediately
  • You're adding TypeScript to an existing JavaScript project with existing JSON data structures
  • You want to generate a base interface from a JSON payload and refine it with more specific types
  • You're documenting an API and need TypeScript type definitions for the docs or SDK
  • You're working with large JSON responses that have dozens of nested fields

Frequently asked questions

Q:How does type inference work?
The generator checks the JavaScript type of each value: strings become string, numbers become number, booleans become boolean, null becomes null, arrays become typed arrays, and nested objects become new named interfaces. Arrays of objects generate a named interface for the element type.
Q:What if my JSON has nullable fields?
If a field's value is null in the sample JSON, it's typed as null. In real APIs many fields can be either a value or null — after generating, manually update these to string | null, number | null, etc. as appropriate for your use case.
Q:Does it handle arrays of objects?
Yes. An array of objects generates a separate interface for the element type and types the field as InterfaceName[]. For example, {"users": [{"id": 1, "name": "Alice"}]} generates a User interface and types the field as users: User[].
Q:Can I use the output with Zod or other schema libraries?
The output is TypeScript interface syntax. For Zod schemas, use the generated interfaces as a reference to write z.object() definitions — or use our dedicated JSON to Zod Schema generator tool.