Skip to content
MyJson

JSON to TypeScript Converter

Infer TypeScript interfaces from a JSON sample.

Root type
Input

Output

1 line
Runs entirely on your device

About JSON to TypeScript

Turn a JSON sample into TypeScript interfaces in one step. MyJson reads the structure of your document and writes types for every object, array and primitive it finds, so an API response or config file can be typed without hand-writing declarations.

Nested objects become named interfaces, arrays of objects are merged into one item type, and fields that are missing in some records are marked optional.

How to use it

  1. 1Paste a JSON sampleUse a real response or record. The more representative it is, the more accurate the types.
  2. 2Name the root typeSet the name of the top-level interface. Nested interfaces are named after their keys.
  3. 3Choose interface or typeEmit interface declarations or type aliases, with or without export keywords.
  4. 4Copy into your projectCopy the output or download a .ts file.

Features

  • Nested objects become named interfaces
  • Array item types merged across records
  • Optional fields detected from missing keys
  • Union types for mixed values
  • interface or type output, with optional export
  • Runs locally in your browser

When to use it

  • Typing an API response in a frontend project
  • Generating models from a JSON fixture
  • Documenting the shape of a configuration file
  • Checking what a third-party webhook actually sends

Frequently asked questions

How are optional fields detected?

When an array contains objects and a key appears in some of them but not all, that key is marked optional in the merged item type.

What happens with null values?

A field that is null in the sample is typed as null. If the same field has another type elsewhere in the document, the result is a union such as string | null.

Is my JSON uploaded?

No. Type generation runs entirely in your browser.

Related tools

Looking to learn more? Browse our JSON guides and tutorials.