πŸ”’ All processing happens in your browser. No data is sent to any server.
FREE

JSON β†’ TypeScript Interface

← All Tools
User API Response Config Array Deeply Nested

JSON Input

TypeScript Output

Output will appear here…

What is JSON to TypeScript Generator?

JSON to TypeScript Generator converts any JSON object or JSON Schema into TypeScript interface and type definitions. Paste a JSON sample and the tool infers all field names, types, optional properties (fields that are null or missing in some examples), and nested object structures β€” outputting production-ready TypeScript interfaces you can copy directly into your codebase.

Writing TypeScript interfaces by hand for large API responses is tedious and error-prone. A 50-field API response with nested objects might take 30 minutes to type manually. This tool converts it in seconds. It handles arrays of objects (inferring element types), union types (when a field is sometimes a string and sometimes null), and optional properties (?) when a key is present in some but not all records in an array.

Generated interfaces follow TypeScript best practices: PascalCase names (User, OrderItem), readonly modifiers for API response fields, proper handling of null vs undefined, and interface vs type alias selection. The output is compatible with TypeScript strict mode and passes standard tsconfig checks.

How to Use

  1. Paste a JSON object or array into the input field.
  2. Enter an interface name (e.g., 'ApiResponse', 'User') or leave blank for auto-generated names.
  3. Toggle 'Optional properties' to mark fields that might be absent as optional (?) vs required.
  4. Toggle 'Readonly' to add readonly modifiers to all properties (recommended for API response types).
  5. Copy the generated TypeScript interfaces and paste them into your project.

Examples

{"id": 1, "name": "Alice", "email": null}

Result: interface User { id: number; name: string; email: string | null; }

[{"id":1,"active":true},{"id":2,"active":false,"score":95}]

Result: interface Item { id: number; active: boolean; score?: number; } β€” score is optional because it only appears in one object

Deeply nested API response with arrays

Result: Generates interfaces for all nested objects and uses interface references (e.g., OrderItem[]) for arrays

Frequently Asked Questions

Can the tool handle arrays?

Yes. Arrays generate a typed element interface and the parent property uses the element type with []. If array elements have different shapes, the tool infers a union type or marks properties as optional.

What is the difference between interface and type alias?

Both work for object shapes in TypeScript. interface supports declaration merging (multiple declarations of the same name merge); type alias does not. Prefer interface for objects you might extend; type for unions, intersections, and mapped types. This tool generates interfaces by default.

How does the tool handle null vs undefined?

JSON has null but no undefined. A JSON field of null becomes string | null (or the inferred type | null). undefined is TypeScript-only β€” use optional (?) for fields that may not be present at all.

Can I generate types for a JSON Schema?

Yes β€” toggle 'JSON Schema input' mode to paste a JSON Schema definition and generate TypeScript types from it. JSON Schema supports more precise constraints (minLength, enum, pattern) that map to TypeScript literal types and union types.

Is the generated code production-ready?

The output is a starting point. Review it for: name accuracy (auto-generated names like 'RootObject' should be renamed), business logic constraints (a 'status' field typed as string might be better as a union type 'active' | 'inactive'), and whether optional vs required is correct for your use case.

Related Tools