Skip to content

JSON to TypeScript Converter Online Free

Last verified May 2026 — runs in your browser
JSON Input
TypeScript Output

JSON to TypeScript — Generate Interfaces & Types (json2ts)

Paste a JSON sample and the generator walks the tree and emits a set of TypeScript interface declarations that describe it: the root becomes a named interface, every nested object becomes its own named interface, arrays become T[], and primitives become their TypeScript equivalents (string, number, boolean, null). The output is ready to paste into a .ts file with no further editing.

Use this to type the response of a new API you are integrating, seed interfaces for a form payload, produce types for a configuration file read at runtime, bootstrap models from a sample record in a mocked fixture, or generate the TypeScript side of a code-generation pipeline where you want to avoid writing interfaces by hand. It is also a fast sanity check when you suspect a backend endpoint is returning a different shape than the types claim.

The generator handles the common shape quirks: arrays of objects with differing keys produce a union type that covers the observed variants, arrays with null entries produce (T | null)[], keys missing from some objects become optional (key?: T), and empty arrays default to unknown[] so you tighten them manually. The full result can be copied or downloaded as a .ts file and regenerates live as you edit the input.

The JSON and the generated TypeScript stay in your browser — nothing is uploaded.

About JSON to TypeScript conversion

TypeScript interfaces describe the shape of JavaScript objects. Generating them from JSON samples saves time when typing API responses, configuration files, or database records.

  • Generates clean TypeScript interfaces
  • Handles nested objects and arrays
  • Detects union types in arrays
  • Download as .ts file
  • Real-time conversion as you type

100% client-side. Your inputs never leave your browser. Ads via AdSense (consent required).

Frequently asked questions

How do I generate TypeScript types from JSON?

Paste a JSON sample and the tool infers the shape and emits TypeScript interface declarations. Each object becomes an interface, nested objects become nested interfaces (with auto-generated names), and arrays are typed as T[]. Optional fields are detected when the tool sees the same key present in some objects and absent in others across an array of samples. Mixed-type arrays become union types like (string | number)[].

Is the JSON to TypeScript converter free?

Yes, completely free with no signup. Generate as many interfaces as you need — useful when an API has no published types and you want to bootstrap a typed client. JSONCraft has no premium tier; every tool is unrestricted. Copy the generated interfaces straight into your project.

Does the converter upload my JSON?

No. Inference and code generation run entirely in your browser. Nothing is sent anywhere, which matters because API responses that you'd want to type often include real data — user IDs, tokens, internal URLs. You can paste production samples safely to generate interfaces for them.

How are optional fields and unions detected?

Pass an array of samples (not a single object) and the tool compares keys across items: keys present in all items are required, keys present in some are marked optional with ?. For primitive values that vary in type across samples (number sometimes, null sometimes), you get a union like number | null. For arrays containing mixed types, you get a union inside the array. A single sample yields all-required interfaces, so always paste arrays when possible.

Should I use interfaces or type aliases?

The tool emits interfaces by default because they are declaration-merged (you can reopen them later) and produce clearer tsc error messages. For union-heavy or mapped shapes, a type alias is more flexible. The practical advice: generate interfaces here, then rename or switch to type where your codebase conventions call for it. Both compile to identical runtime (nothing — TypeScript types are erased).

By ·