Skip to main content

JSON Input

Opzioni

TypeScript Output

Incolla un JSON per generare i tipi TypeScript

Come utilizzare TypeScript Type Generator

Attach the JSON

Attach an object or a pre-compiled JSON array to the input field, or load the example to see the result immediately.

Configure options

Choose the name of the root interface, if using "interface" or "type", add "export", optional fields, read-only, or nullable.

Copy generated code

The right panel shows generated TypeScript code in real-time: use the "Copy" button to paste it directly into your project.

Suggerimenti

  • If the JSON is an array, the tool generates automatically an interface for a single element and a type alias for the entire array.
  • Activate "Read-only fields" when generating types for immutable data (e.g., API responses) to avoid accidental code mutations.
  • Use a descriptive root name (e.g. "User", "OrderResponse") instead of the default "Root" to get more readable interfaces without having to rename them manually.

Domande frequenti

How are types derived from JSON values?

The tool recursively analyzes every value: strings become "string", numbers become "number", booleans become "boolean", arrays are typed based on their contents, and nested objects generate nested interfaces.

What happens when an array contains elements of different types?

The tool collects all distinct types found in the array elements and generates a union type, for example "(string | number)[]", to accurately reflect the provided sample data.

What is the difference between generating "interface" and "type"?

They are equivalent for describing the shape of an object: "interface" and "extends" and "declaration merging", "type" and more flexible for union and intersection types. The choice is a style preference of the project, the tool supports both syntaxes.

Why aren't optional or nullable fields automatically detected?

The tool works on a single JSON example, so it can't know which fields are truly optional in other records of the same type. Use the checkboxes "Optional Fields" and "Nullable" to apply these patterns manually to all generated fields.

Is JSON being sent to a server for conversion?

No, type generation occurs entirely in the browser client-side; no JSON data is sent to an external server, you can use the tool with sensitive data or internal payloads.