Skip to content

JSON to TypeScript. Paste JSON, ship types.

Emit as

Your JSON never leaves your browser, nothing is uploaded.

TypeScript Waiting for input…

            

Codegen without the round-trip

Paste an API response, a config file or any JSON object and the converter infers a full type model on your device: nested objects become their own named interfaces, arrays of objects are merged so a key missing from some items comes out as an optional ? property, and small repeated string sets become literal unions like 'shipped' | 'pending'. Choose interfaces or type aliases, T[] or Array<T>, how nulls are treated, quotes, semicolons and indentation, then copy the result or download a ready-to-import .ts file. No account, nothing uploaded, free forever.

§ · written guide

How to use the JSON to TypeScript converter

This converter reads a JSON value and writes TypeScript interfaces or type aliases that describe it. It walks every object and array, gives each nested object its own named type, and merges the items of an array so keys that only some items have come out optional. Use it to type an API response, a config file or test fixtures without writing the shapes by hand.

Step by step

  1. Paste or load your JSON

    Paste into Input JSON, or press Load .json to pick a file, or drop a file on that button. Files up to 15 MB are accepted. The page opens with a sample user record already converted, and Sample brings it back at any time.

  2. Name the root type

    Type a name in Root type name. It defaults to Root. Nested types are named from it, so with Prefix nested names ticked an address field becomes RootAddress.

  3. Choose interface or type alias

    Under Emit as, pick interface or type alias. If the top level of your JSON is an array or a plain value rather than an object, the converter also writes one type line for the root, such as export type Root = RootItem[].

  4. Set the output style

    Pick Arrays as T[] or the generic Array form, Quotes as single or double, Null values as union | null, make optional or ignore null, Unknown values as unknown or any, and Indent as 2 spaces, 4 spaces or Tab. The output updates as soon as you change one.

  5. Turn the switches on or off

    export keyword, Detect optional props, Semicolons, Prefix nested names and Small string sets as literal unions are on by default; readonly props is off. Typing in the input regenerates the types about a third of a second after you stop.

  6. Copy or download

    Press Copy TypeScript to put the result on your clipboard, or Download .ts to save it. The file is named after the root type in lower case, so the default name gives root.ts. Clear empties the input.

Reading the result

  • The status above the output shows how many types were written and how many lines they take, such as 3 types · 22 lines for the sample. If the input does not parse, the status reads Invalid JSON and the output pane shows the parser's message instead of types.
  • A ? after a key means some items in an array had that key and others did not. In the sample, only one of the two orders has a note, so RootOrder gets note?: string.
  • A union of quoted strings, like status: 'shipped' | 'pending', means that field was seen at least twice with 4 or fewer different values.
  • A field that is only ever null comes out as null with union | null, and as unknown (or any) with the other two null settings, because there is no other value to learn a type from.

Tips and common mistakes

  • Feed it a response with several array items, not just one. Optional detection only works by comparing items, so a single item makes every key required.
  • Literal unions come from your sample, not from the API's rules. In the sample, sku becomes 'A-100' | 'B-220'. Untick Small string sets as literal unions for open text fields like ids and names.
  • Field names that are not valid identifiers, such as first-name, are written in quotes so the type still compiles.
  • If two nested objects would get the same name, the second one gets a number on the end, such as RootItem2. Rename it in your editor if that reads badly.
  • The JSON must be strict JSON. Comments, trailing commas and single quoted strings show Invalid JSON.

Privacy and limits

Parsing and type generation run in your browser. Pasted JSON and loaded files are read on your device and are not uploaded or saved, so reloading the page brings back the sample. Files larger than 15 MB are refused.

Back to the tool

§ 02 · what you can do

Everything a converter should do.

  • Convert JSON to TypeScript interfaces or type aliases the moment you paste, no button to press.
  • Auto-detect optional properties by merging shapes across array items, so ragged API data types honestly.
  • Generate literal union types for small string sets (up to 4 unique values) like status or role fields.
  • Control the output style: export keyword, readonly props, semicolons, quotes, T[] vs Array<T>, null and unknown handling, nested-name prefixes and indent size.
  • Copy or download a ready-to-use .ts file named after your root type.
  • Load any .json file by dropping it onto the page, read locally, never uploaded.
§ 04 · faq

Frequently asked questions.

Is JSON to TypeScript free?
Yes, completely free for everyone. No sign-up, no account and no usage limits.
Is it private? Is my JSON uploaded anywhere?
No upload, ever. Parsing and type generation run entirely in your browser on your own device, your JSON never leaves your computer, whether you paste it or load a file.
Does it work offline?
Yes, once the page has loaded, conversion keeps working without a connection, because all the logic runs locally in your browser. Nothing is installed and no server is involved.
How does optional-property detection work?
The converter merges the shape of every object in an array. If a key appears in some items but not all, like a note field on only one order, it's emitted as an optional property with a ?. You can also make null-valued fields optional via the "Null values" option.
When are literal union types generated?
When a string field is seen at least twice and has 4 or fewer unique values, a typical status or role field, it becomes a literal union like 'shipped' | 'pending' instead of plain string. Untick "Small string sets as literal unions" to always emit string.
Can I load a .json file instead of pasting?
Yes, drop a file onto the "Load .json" zone or click it to browse, up to 15 MB. The file is read with your browser's FileReader API on your device; it is never transmitted anywhere.

Published · Last updated .

Priya sent you a message Online now

Talk to a Developer Now

Share your name and email to reply.

Reply