Paste your JSON below to generate TypeScript interfaces:
Why Generate TypeScript from JSON?
TypeScript interfaces provide type safety for your JSON data. Instead of manually writing interfaces, generate them automatically from API responses or sample JSON data.
Example Conversion
Input JSON:
{
"id": 1,
"name": "John Doe",
"email": "john@example.com",
"isActive": true
}Generated TypeScript:
interface User {
id: number;
name: string;
email: string;
isActive: boolean;
}Features
- Nested object support — Creates separate interfaces for nested objects
- Array type inference — Detects array item types automatically
- Custom root name — Name your root interface anything you want
- Special character handling — Properly quotes keys with special characters
Type Inference Rules
| JSON Value | TypeScript Type |
|---|---|
"string" | string |
123, 45.67 | number |
true, false | boolean |
null | null |
[1, 2, 3] | number[] |
["a", 1] | (string | number)[] |
{ ... } | Separate interface |
Handling Nested Objects
Nested objects automatically get their own interfaces with descriptive names:
// Input
{
"user": {
"profile": {
"name": "John"
}
}
}
// Output
interface RootUserProfile {
name: string;
}
interface RootUser {
profile: RootUserProfile;
}
interface Root {
user: RootUser;
}Working with API Responses
Common workflow for typing API data:
- Make an API request and copy the JSON response
- Paste it into this tool
- Name the root interface (e.g.,
ApiResponse) - Copy the generated interfaces to your TypeScript project
- Use with
fetchor your HTTP client
// Usage in TypeScript
const response = await fetch('/api/users');
const data: User[] = await response.json();
// Now you have full type safety
data.forEach(user => {
console.log(user.name); // TypeScript knows this is a string
});Pro Tips
- 💡 Use representative data — Include all possible fields in your sample JSON for complete interfaces
- 💡 Handle optional fields — If a field might be missing, manually add
?after generation - 💡 Union types — For fields that can be multiple types, consider using union types manually
- 💡 Validate first — Use the JSON Validator to ensure your JSON is valid before converting
Limitations
- Cannot detect optional properties (all properties are required)
- Cannot infer union types for non-array values
- Date strings are typed as
string, notDate
For these cases, manually adjust the generated interfaces after copying.
Related Tools
- JSON Validator — Validate your JSON first
- JSON Schema Validator — Another way to define JSON structure
- JSON to CSV — Export JSON data
Common Mistakes & Pro Tips
- A single sample can't reveal optional fields — The generator infers types from one JSON object, so a property that happens to be present is marked required even if your real data sometimes omits it. After generating, manually add `?` to fields that are sometimes absent (e.g. `avatar?: string`) — otherwise the compiler will demand them everywhere.
- null becomes a union, not optional — A value of `null` in the sample produces a type like `string | null`, which is different from an optional `string?`. `T | null` means the key is present but may be null; `T?` means the key may be missing. If both can happen, you want `field?: T | null`.
- Mixed-type arrays collapse to unions or any — An array like `[1, "two", true]` yields `(number | string | boolean)[]`, and an array of differently-shaped objects produces a union of interfaces. An empty array `[]` gives no element information, so it defaults to `any[]` — narrow it manually to the real element type.
- Every JSON number is just `number` — TypeScript has a single `number` type, so there is no int/float distinction and no `bigint` inference. If a field holds a 64-bit integer ID that exceeds Number.MAX_SAFE_INTEGER, keep it as a `string` in your API and type it as `string`, because JSON.parse will silently lose precision.
- Keys that aren't valid identifiers get quoted — JSON keys like `"first-name"`, `"2fa"`, or keys with spaces can't be bare identifiers, so they're emitted as quoted property names (`"first-name": string`). Access them with bracket notation (`obj["first-name"]`), and remember the JSON key is preserved exactly — TypeScript does no camelCase conversion at runtime.
Frequently Asked Questions
Should I generate `interface` or `type`?
Use `interface` for object shapes you may want to extend or merge later; it gives clearer error messages and supports declaration merging. Use `type` when you need unions, intersections, mapped types, or tuples — things `interface` can't express. For plain JSON-shaped data both work, and you can freely mix them.
How do I handle optional or nullable fields the tool didn't catch?
Because inference comes from one sample, add `?` for keys that may be absent and `| null` (or `| undefined`) for values that may be null. A common safe pattern for API responses is `field?: string | null`. If many fields are optional, consider wrapping the whole type in `Partial<T>` rather than annotating each one.
Why are my date strings typed as `string` instead of `Date`?
JSON has no date type — an ISO timestamp like `"2026-06-11T10:00:00Z"` is just a string, so the generator correctly types it as `string`. `JSON.parse` will not turn it into a `Date`. If you want `Date` objects, convert them yourself (e.g. with a reviver function or `new Date(value)`) after parsing.
Will these types validate my data at runtime?
No. TypeScript interfaces are erased at compile time and provide zero runtime checking, so a malformed API response can still pass `as MyType` and crash later. For runtime validation, pair the generated shape with a library like Zod, io-ts, or Valibot, or derive the type from a Zod schema instead.
How are nested objects handled?
Each nested object becomes its own named interface, referenced by the parent (e.g. a `user` field gets a `User` interface). Deeply nested structures produce a tree of interfaces. You can also choose inline object literal types, but named interfaces are usually more reusable and readable.
Is my JSON uploaded to a server?
No. This tool runs entirely in your browser using JavaScript — your JSON is parsed and converted locally and never leaves your machine. That makes it safe to paste internal API payloads or data containing secrets without it touching any network.