JSON to TypeScript Interface Generator

Private
Output
Examples:

Last updated: 2026-09-17

Paste a JSON object or array and get type definitions instantly. Choose from TypeScript interfaces, TypeScript type aliases, Zod schemas, Go structs, Pydantic models, or C# classes — all from the same page. When your input is an array of objects with varying keys, the converter infers which fields are optional. Toggle readonly properties for immutable types.

Union types from mixed arrays

When an array contains elements of different types (e.g. strings and numbers), the converter generates a union type. In TypeScript this is string | number; in Go and C# it falls back to the most general type (interface{}/object).

Empty arrays

Empty arrays produce unknown[] in TypeScript, Listin Go/Dart, list[Any] in Pydantic, and Listin C#. The element type cannot be inferred without at least one sample.

C# nullable

The C# output uses reference types without nullable annotations. If you are using C# 8+ nullable reference types, add ? to string and class-type properties as needed.

Frequently asked questions

How are optional fields inferred?
When you provide an array of objects and enable "Infer optional fields", the converter checks which keys appear in every element versus only some. Keys missing from any element are marked optional with the ? modifier. Keys present in all elements are required.
What is the difference between interface and type alias?
TypeScript interfaces support declaration merging and are the conventional choice for object shapes. Type aliases are more flexible (can represent unions, primitives, conditional types) but cannot be merged. For plain object types, they are functionally equivalent.
How are numbers typed in Go?
All numbers become float64 in Go structs, since JSON does not distinguish integers from floats and JavaScript numbers are all doubles. You can manually change float64 to int for fields you know are integers. The json tag is added for encoding/json compatibility.
How does the Zod schema output work?
The converter generates a z.object() schema with proper z.string(), z.number(), z.boolean() calls. Nested objects become separate schemas referenced by name. Arrays use .array(). Optional fields use .optional(). Union types use z.union().
Can I generate Pydantic models for Python?
Yes. The output uses Pydantic v2 syntax with BaseModel. Types use Python 3.9+ type hints (list[str] instead of List[str]). Optional fields use the | None syntax. You need pydantic installed in your Python environment.
How are null values handled?
JSON null becomes the type null in TypeScript, interface{} in Go, None in Pydantic, and object in C#. If a field is null in a single sample, it is typed as null — consider providing multiple samples to get more accurate types.

Related converters