JSON to TypeScript
Paste JSON → get clean TypeScript interfaces (or type aliases) with proper nesting, optional fields, and union arrays. 100% client-side.
About the JSON to TypeScript Generator
When working with external APIs, you receive JSON responses that need TypeScript types for type-safe access in your code. Writing interfaces by hand is tedious for complex nested structures. This tool generates TypeScript interfaces or type aliases from any JSON sample, with options for strict mode, readonly properties, and optional fields.
What this tool generates
Interfaces
TypeScript interface declarations with nested interfaces for object properties. Extendable and compatible with declaration merging.
Type Aliases
TypeScript type aliases — more flexible than interfaces, supporting union types for mixed-type arrays and nullable fields.
Type Inference
Infers string, number, boolean, null, arrays, and nested objects from JSON values.
Optional Properties
Marks properties as optional (?) when they are null or absent in some array elements — accurate for real-world API responses.
Pipeline
- JSON Formatter — validate and pretty-print your JSON before generating types.
- JSON Schema Generator — generate a JSON Schema for runtime validation alongside your TypeScript types.
- JSON to Apex — generate Apex wrapper classes for the same payload.
Frequently asked
- Is my JSON data sent to a server?
- No. All TypeScript generation runs 100% in your browser. Your JSON payloads never leave your device.
- What is the difference between interface and type alias output?
- Interfaces are extendable via declaration merging and are preferred for object shapes. Type aliases are more flexible — they can represent unions, intersections, and primitives. For API response types, both work; interfaces are the TypeScript team's recommendation for object types.
- How does the tool handle arrays?
- Arrays are typed as T[] where T is inferred from the array elements. If the array contains mixed types, a union type is generated. Empty arrays are typed as unknown[] since the element type cannot be inferred.
- What does "strict" mode do?
- Strict mode generates more precise types: optional properties (?) for fields that are null or missing in some array elements, readonly modifiers for immutable data, and never for empty objects. Non-strict mode generates simpler, more permissive types.
- Can I use the generated types with JSON.parse?
- TypeScript types are erased at runtime — JSON.parse always returns any. You need a runtime validation library like Zod, io-ts, or Valibot to validate the parsed data against your types. The generated types are useful for type-checking code that handles the data after validation.