json | typescript | interface

> json | typescript | interface <

// Convert JSON objects to TypeScript interfaces or type aliases instantly

[NESTED]

Deep Nested Support

Recursively generates separate named interfaces for nested objects, keeping each definition clean and reusable.

[OPTIONAL]

Optional Field Detection

Marks fields as optional (with the ? modifier) automatically when null values are detected in the JSON sample.

[FLEXIBLE]

Interface or Type Alias

Toggle between TypeScript interface declarations and type alias declarations to match your project conventions.

// ABOUT JSON TO TYPESCRIPT

How It Works:

The converter parses your JSON (per RFC 8259, the JSON specification) and walks the object tree recursively. Each nested object becomes a separately named interface (Root, Address, User, etc.) following the conventions described in the official TypeScript Handbook. Primitive values become string, number, or boolean. Arrays are typed as Type[] when uniform, or as a union when mixed. Null values flag the parent field as optional.

Example:

{"id": 1, "name": "Alice"} becomes interface Root { id: number; name: string; }

Common Use Cases:

  • >Bootstrap TypeScript types from API JSON responses
  • >Migrate JavaScript projects to TypeScript
  • >Generate DTOs for fetch and axios calls
  • >Document JSON contracts as readable types
  • >Speed up frontend development with autocomplete

>> frequently asked questions

Q: How are optional fields detected?

A: A field is marked optional (with the ? modifier) only when its value is null in the JSON sample provided. If you have multiple JSON payloads to merge into one shape, paste an array of objects and the tool will union the keys across each entry, marking any key that is missing or null in some entries as optional.

Q: What is the difference between interface and type?

A: TypeScript interface declarations are open and can be merged across files via declaration merging; type aliases are closed and support unions, intersections, and mapped types more directly. Both work for describing object shapes, so pick the one that matches your project's house style. The TypeScript Handbook recommends interfaces for public APIs.

Q: Does it support arrays of objects?

A: Yes. Arrays of objects produce a single named interface for the element type and an array reference (e.g. Items[]) on the parent field. Mixed-type arrays produce a union element type such as (string | number)[]. The tool merges keys across all elements to build the most accurate shared shape.

Q: Can it handle deeply nested JSON?

A: Yes. Each nested object level produces its own named interface so the output stays flat and readable, no matter how deep the structure goes. Names are derived from the parent property, with PascalCase normalization, and collisions are resolved by appending a numeric suffix to keep every generated name unique.

Q: Is my data sent to a server?

A: No. The conversion runs entirely in your browser using the native JSON.parse function and a small recursive type walker. Nothing is uploaded or logged, so the tool is safe for sensitive payloads such as internal API responses, authentication payloads, and pre-release schemas you have not yet documented publicly.

// OTHER LANGUAGES