Skip to content

JSON to TypeScript - Generate Types from JSON Online

Input JSON
TypeScript Output

About JSON to TypeScript

Working with external APIs usually means dealing with raw JSON that has no type information. You copy a response, stare at the nesting, and start writing interfaces by hand. This tool skips that step. Paste any JSON document and get a full set of TypeScript interfaces you can drop straight into your codebase.

The converter handles deeply nested objects, arrays of mixed types, and edge cases like empty arrays or primitives at the root level. Every generated interface is exported and named in PascalCase so it plugs into your project without extra cleanup.

How to Use It

Paste your JSON into the left editor. The TypeScript output updates automatically in the right pane. If you want a different root interface name, type it into the field above the editors. Once you are happy with the result, use the copy button to grab the output and paste it into your .ts file.

Features

  • Recursive interface generation. Nested objects each get their own named interface instead of inline object types.
  • Array type inference. Element types are detected automatically, and mixed arrays produce union types.
  • Custom root name. Set the top-level interface name to match your project conventions.
  • Instant feedback. Output updates on every keystroke with no manual submit button required.
  • Client-side only. Your data never leaves the browser.

Common Use Cases

Front-end developers use this tool after hitting a new REST endpoint for the first time. Instead of manually writing types for a 200-line response, paste the payload and get interfaces in seconds. It is also handy when joining a project that has untyped API layers, or when generating types for mock data in test files.

Frequently Asked Questions

How does this tool infer TypeScript types from JSON?
The tool parses your JSON and walks the structure recursively. Strings become `string`, numbers become `number`, booleans become `boolean`, and null becomes `null`. Objects generate named interfaces with each key as a property, and arrays are typed based on the first element. Empty arrays become `unknown[]`.
Does it handle nested objects?
Yes. Every nested object gets its own named interface in PascalCase derived from the key name. For example a key called `shipping_address` produces an interface named `ShippingAddress`.
What happens if array items have different shapes?
The tool inspects each element and unions their types. If an array contains both strings and numbers, the resulting type will be `(string | number)[]`.
Can I change the root interface name?
Absolutely. There is an input field above the editors where you can set any name you like. It defaults to `Root`.
Is my JSON sent to a server?
No. All conversion happens in your browser using JavaScript. Nothing leaves your machine.