🧩 JSON to TypeScript Interface Generator
By ToolNimba Engineering Team · Updated 2026-06-19
Paste JSON above, then press Generate interfaces.
Paste a JSON object or array and this tool generates the matching TypeScript interfaces for you. It walks the data, infers each field type (string, number, boolean, null), turns nested objects into their own named interfaces, and maps arrays to T[]. You set the root interface name, choose whether to export, and copy the result straight into your project. Everything runs in your browser, so your JSON never leaves the page.
What is the JSON to TypeScript?
TypeScript needs to know the shape of your data to give you autocompletion and compile-time safety, but writing interfaces by hand from a sample API response is tedious and error prone. This generator does it mechanically: it parses your JSON, then for every key it reads the value and emits the corresponding TypeScript type. A text value becomes string, a number becomes number, true or false becomes boolean, and null becomes null (or an optional field if you turn that option on).
Nested structures are where hand-writing gets painful, and where the tool earns its keep. When a property holds another object, the generator creates a separate named interface for it (derived from the property name in PascalCase) and references that interface by name, so you get a clean, flat set of declarations rather than one deeply nested blob. Arrays are inferred to an element type and written as ElementType[]. When an array holds objects, their shapes are merged into one shared interface, and any key that is missing from some elements is marked optional with a question mark.
Keep in mind that JSON is only a sample, not a schema. The generator can only describe the exact data you paste: it cannot know that a field is sometimes null, that a number is really an enum, or that an empty array would normally hold strings. Treat the output as a strong first draft. Review the inferred types, widen any that are too specific, add unions or optional markers the sample did not reveal, and rename the auto-generated interfaces to match your domain language.
When to use it
- Turning a sample REST or GraphQL API response into typed interfaces before you write the client code.
- Bootstrapping types for a config file, fixture, or mock data object you already have as JSON.
- Migrating a JavaScript project to TypeScript by generating starting interfaces from runtime data.
- Quickly checking the shape of an unfamiliar JSON payload by reading its generated structure.
How to use the JSON to TypeScript
- Paste your JSON object or array into the input box (it must be valid JSON, with double-quoted keys).
- Type a name for the root interface, for example User or ApiResponse.
- Optionally tick to mark null fields as optional, and choose whether to add the export keyword.
- Press Generate interfaces, then copy the TypeScript output into your project.
Formula & method
Worked examples
A flat object: { "id": 1, "name": "Ada", "active": true }, root name User.
- id holds a number, so id: number
- name holds a string, so name: string
- active holds true, so active: boolean
- Wrap the three properties in interface User { ... }
Result: export interface User { id: number; name: string; active: boolean; }
A nested object: { "user": { "city": "London" } }, root name Data.
- Data is registered first as the root interface
- user holds an object, so it becomes its own interface named User
- Inside User, city holds a string, so city: string
- Emit Data first referencing User, then the User interface
Result: export interface Data { user: User; } export interface User { city: string; }
An array of objects with a missing key: [ { "x": 1, "y": 2 }, { "x": 3 } ], root Point.
- Both elements are objects, so their shapes merge into one interface
- x appears in every element, so x: number
- y appears in only one element, so it becomes optional: y?: number
- The element interface is named PointItem, and Point aliases PointItem[]
Result: export interface PointItem { x: number; y?: number; } export type Point = PointItem[];
How JSON values map to inferred TypeScript types
| JSON value | Inferred TypeScript type |
|---|---|
| "hello" | string |
| 42 or 3.14 | number |
| true / false | boolean |
| null | null (or optional field if option set) |
| { ... } | a named interface (PascalCase from the key) |
| [1, 2, 3] | number[] |
| [ {...}, {...} ] | a merged interface, written as Name[] |
| [] (empty) | any[] |
Generator options and what they do
| Option | Effect |
|---|---|
| Root interface name | Names the top-level interface or type alias. |
| Mark null fields optional | Renders a null property as name?: null instead of required. |
| Add export keyword | Prefixes each interface with export for module use. |
Common mistakes to avoid
- Trusting a single sample as the full schema. JSON shows one snapshot of the data. A field that happens to be filled in your sample might be null or missing in real responses. Review the output and add optional markers or unions the sample did not reveal.
- Pasting JavaScript object literals instead of JSON. The input must be strict JSON: keys in double quotes, no trailing commas, no comments, and no unquoted identifiers. If you copy a JS object you may need to quote the keys first, or the parse will fail.
- Expecting literal or enum types automatically. A value of "active" becomes string, not the literal "active". The tool cannot guess that a field is one of a fixed set, so narrow strings to union literal types yourself where it matters.
- Leaving auto-generated nested interface names as-is. Names are derived from property keys, so deeply nested or repeated keys can produce generic or numbered names. Rename them to meaningful domain terms before committing the types.
Glossary
- Interface
- A TypeScript construct that describes the shape of an object: which properties it has and their types.
- Type inference
- Working out a type automatically from a value, rather than writing it out by hand.
- Optional property
- A property marked with ? that may be present or absent on an object without a type error.
- Union type
- A type that allows one of several alternatives, written with the pipe symbol, such as string or number.
- PascalCase
- A naming style where each word starts with a capital letter and there are no separators, used here for interface names.
Frequently asked questions
How do I convert JSON to a TypeScript interface?
Paste your JSON into the input box, give the root interface a name, and press Generate interfaces. The tool reads each field, infers its type, turns nested objects into their own interfaces, and outputs ready-to-copy TypeScript.
Does it handle nested objects and arrays?
Yes. Each nested object becomes its own named interface referenced by the parent. Arrays are written as ElementType[], and an array of objects has its element shapes merged into a single shared interface.
What happens with null values?
By default a null value is typed as null. If you tick the option to mark null fields optional, that property is rendered with a question mark instead, which is often what you want for fields that may be absent.
Why are some fields marked optional with a question mark?
When you give an array of objects, the generator merges their shapes. Any key that appears in some elements but not all is marked optional, since it is not guaranteed to be present on every object.
Is my JSON sent anywhere?
No. The whole conversion runs in your browser using the built-in JSON parser. Nothing is uploaded, logged, or sent over the network, so it is safe to paste private or internal data.
Why did I get an Invalid JSON error?
The input must be strict JSON: property names in double quotes, no trailing commas, no comments, and no single quotes. The error message shows where parsing failed so you can fix that spot and try again.