FileToolsHub logo

JSON to TypeScript Interface Generator

Paste JSON and generate a TypeScript interface with inferred types — nested objects and arrays included, in your browser.

An empty tags array is unknown[]. A blank name still prints Root.
Root sample with id, name Ada, active, and tags dev
export interface Root with number, string, boolean, and string array

Processing: runs in your browser, nothing uploaded

✓ Free to use✓ No sign-up needed✓ Nothing to install

About JSON to TypeScript Interface Generator

JSON to TypeScript reads one sample and writes an interface. The opening sample uses the name Root, with id, name, active, and a tags array.

The Root sample

The opening JSON has id 1, name Ada, active true, and tags holding the string dev. Convert to TypeScript writes export interface Root, then a block. id is number. name is string. active is boolean. tags is string followed by square brackets. The interface name field starts as Root. Clearing that field still uses Root, because a blank name falls back to Root. Copy changes to Copied after the text is on the clipboard. An empty JSON box throws Unexpected end of JSON input and clears the output. A lone opening brace stops at position 1 with the JSON parse error. An empty tags array is typed as unknown array. A key written a b is quoted in the interface.

What one sample cannot say

Only the first value of an array is inspected. A later value of a different type does not create a union. Optional keys are not marked, because a missing key in this sample is simply absent. Enums are not inferred. An empty object becomes Record of string to unknown, which is not a brace-shaped interface body. A top-level array or a bare number is wrapped in the same export interface line, so the result is not valid TypeScript until you edit it. There is no download. Nested objects are named from the parent name plus the key, with non-letters removed. The page does not call a compiler.

How to check Root

Leave the sample and the name Root, then press Convert to TypeScript. The first line should be export interface Root. id should say number. tags should say string with square brackets. Clear the JSON and expect Unexpected end of JSON input with an empty output. Change tags to an empty array and expect unknown with square brackets. Add a key that contains a space and expect that key in quotes. If the line says type instead of interface, the text did not come from this button. Copy should switch to Copied. A blank interface name should still print Root.

The sample stays in this tab

The inference runs in this browser. The JSON is not uploaded. Closing the tab drops the sample and the interface. Nothing is stored. Convert to TypeScript is the only convert control. The output is a string you copy. Empty tags become unknown array. A spaced key is quoted. The first array element is the only one that sets the element type. A second element is ignored for typing. Root is the fallback name when the name field is blank. The page does not check that the interface compiles. The opening sample uses id 1, the name Ada, active true, and tags holding the string dev. Convert to TypeScript is the button, and Copy switches to Copied after the clipboard write.

How to use

  1. 1

    Leave the Root sample, or paste another object.

  2. 2

    Press Convert to TypeScript.

  3. 3

    Copy the interface. An empty box clears the output.

Privacy

Inference runs in this browser. The JSON sample is not uploaded. Closing the tab drops the interface.

Frequently asked questions

What types does the Root sample get?

id is number, name is string, active is boolean, and tags with dev inside is a string array.

What if the interface name is blank?

The line still says Root. A blank name falls back to Root.

What does an empty tags array become?

unknown with square brackets. Only the first array value is used when the array is not empty.

What does a bad JSON sample say?

An empty box throws Unexpected end of JSON input and the output is cleared.

Does the interface generator upload the sample?

No. Inference runs in this browser and the JSON is not uploaded.

Browse all Text Tools · Sitemap