JSON to TypeScript. Paste JSON, ship types.
Your JSON never leaves your browser, nothing is uploaded.
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.
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
-
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.
-
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.
-
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[].
-
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.
-
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.
-
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.
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.
Frequently asked questions.
Is JSON to TypeScript free?
Is it private? Is my JSON uploaded anywhere?
Does it work offline?
How does optional-property detection work?
When are literal union types generated?
Can I load a .json file instead of pasting?
Published · Last updated .