DevToolsForYou
Private by defaultRuns in your browser

JSON to TypeScript interface

Paste JSON and get TypeScript interfaces instantly — nested objects, arrays, nullables, and union types all inferred automatically.

Samples:
TypeScript interfaces will appear here…
JSON → TS

About this tool

Paste any JSON object and instantly get clean TypeScript interfaces with correctly inferred types — nested objects, arrays, optional fields, and union types all handled automatically.

No signup requiredRuns in your browserInstant results
How to use
  1. 1

    Paste a JSON object or array into the input box.

  2. 2

    The TypeScript interface is generated instantly as you type.

  3. 3

    Use the root interface name field to customise the top-level interface name (default: Root).

  4. 4

    Toggle optional fields (?) if you want all properties marked as optional.

  5. 5

    Copy the output with the Copy button and paste into your TypeScript project.

Why use this tool?
  • Generate TypeScript interfaces from a REST API response to type your fetch calls.

  • Convert a large JSON config file to typed interfaces for safer access.

  • Bootstrap types for a new feature from a sample API payload.

  • Turn a Postman response body into TypeScript types without writing them by hand.

ExamplesInput → output

Simple object

Input{"id":1,"name":"Alice","active":true}
Outputinterface Root { id: number; name: string; active: boolean; }

Nested

Input{"user":{"id":1,"address":{"city":"NYC"}}}
OutputNested interfaces: IUser, IAddress
Common errorsAnd how to fix them

Invalid JSON

Cause: The pasted text is not valid JSON — common issues are trailing commas, single quotes, or unquoted keys.

Fix: Validate your JSON first (use a JSON formatter), then paste again. Make sure you paste an object or array, not a plain string or number.

Root value must be an object or array

Cause: You pasted a JSON primitive (string, number, boolean) rather than an object or array.

Fix: Wrap the value in an object, e.g. { "value": 42 }, so the generator has properties to convert.

Frequently asked questionsCommon questions answered

These answers explain common json → ts tasks, expected input formats, and edge cases so both visitors and search engines can understand what this tool does.

How are array types inferred?

The generator samples all elements of the array and merges their types. If the array contains objects of varying shapes, the properties are unioned. If it contains mixed primitives (e.g. number and string), the type becomes (number | string)[].

What happens with null values?

A null value produces a type of null. If the same key has both a non-null value and null across array elements, the type is inferred as T | null.

Are all properties marked as optional?

By default, properties are required. Toggle the 'All optional' switch to add ? to every property — useful when the JSON is a partial payload.

How are interface names derived?

Nested object keys are PascalCased and prefixed with I (e.g. a key 'userProfile' becomes IUserProfile). You can rename the root interface in the input field.