JSON to TypeScript

Turn a JSON sample into a TypeScript interface in your browser — a quick starting type for an API response. Honest note: it infers from one sample, so refine it by hand.

Developer Tools Free No upload Instant

Loading JSON to TypeScript…

Your browser is preparing the tool. It runs 100% locally.

Quick Answer

Paste a JSON sample and the tool generates a matching TypeScript interface, reading each value to pick number, string, boolean, an array type or a nested object. It is a fast way to get a starting type for an API response. Because it works from a single sample, every field comes out required, and it cannot spot optional or union types — so treat the result as a first draft to refine. It runs entirely in your browser; nothing is uploaded.

What the JSON to TypeScript Does

This tool reads a JSON object and writes a TypeScript interface that describes its shape, assigning each property a type based on its value and turning nested objects into nested types. The output is ready to paste into your code as a starting point.

It is the quick way to stop hand-writing interfaces for API responses and config objects: give it a representative sample and it gives you a typed skeleton in seconds.

How It Works

The tool parses the JSON, then walks each property and infers a type from its value — a number becomes number, text becomes string, true or false becomes boolean, an array becomes a typed array, and a nested object becomes a nested interface. It assembles these into an interface it names Root.

Everything is inferred from the one sample you provide. That makes it fast, but it also means the result reflects only what is in that sample: the tool sees one example of each field and types it accordingly, with no knowledge of how the data varies across other records.

Data source & conversion logic

  1. Parse the JSON. Read the sample into a data structure, which also checks it is valid JSON.
  2. Infer each field's type. Map each value to a TypeScript type — number, string, boolean, array or nested object.
  3. Type the arrays. Take an array's type from its first element, or any for an empty array.
  4. Assemble the interface. Combine the typed fields into an interface named Root, ready to copy.

How types are inferred

number → number text → string true/false → boolean array → (type of first element)[] object → nested interface null → any every field is required (no optional ? from a single sample)
Worked example
{ id: 1, name: x, active: true, tags: [a] } → interface Root { id: number; name: string; active: boolean; tags: string[]; }

Inferred from one sample, so every field is required and arrays take the type of their first element. Optional fields and unions need multiple samples, which this tool does not take.

Privacy

Your JSON never leaves your device. The interface is generated in your browser with no network request, so nothing is uploaded.

Because the work is local, you can generate types from real API payloads or internal data without it being stored or sent anywhere.

Nothing persists between sessions — close the tab and the JSON and the generated type are gone.

Standards & references

  • TypeScript interfaces — An interface describes the shape of an object — its property names and their types. Generating one from JSON gives you compile-time checking for data that arrives as plain JSON at runtime.
  • Single-sample inference — Types are inferred from one example. That cannot reveal which fields are sometimes absent (optional) or which hold more than one type (unions) — information that only appears across multiple, varied samples.
  • Multiple samples for richer types — Tools like quicktype take several JSON samples: a field missing from some becomes optional, and a value with different types becomes a union. Three to five diverse samples give the most accurate types.

Accuracy & Limitations

For a representative sample, the interface is a correct, useful starting type — the field names and basic types match the data, ready to drop into your code and refine.

Every field comes out required. Because it sees one sample, the tool cannot know which properties are optional, so a field that is sometimes missing in real data will still be typed as always present. Add the optional marker by hand where needed.

It cannot infer unions. A field that is a number in one record and a string in another, or an array of mixed types, is typed only from this sample. Arrays in particular take the type of their first element, so a mixed array is typed wrongly and an empty array becomes an array of any.

Nested objects become inline anonymous types rather than separate named interfaces, a null value becomes any, and everything is named Root. For a polished set of named, optional and union types, generate from multiple samples with a dedicated tool.

Real-World Use Cases

Typing an API response

Get a starting interface from a sample response payload.

Stop hand-writing types

Generate a typed skeleton instead of typing each field.

Modelling config objects

Turn a JSON config into a TypeScript shape.

Learning TypeScript types

See how JSON values map onto TypeScript types.

When to use it — and when not to

Good for

  • A quick starting interface from a sample
  • Typing a straightforward API response
  • Turning a JSON config into a type
  • Learning how JSON maps to TS types

Not the best choice for

  • Optional fields (everything comes out required)
  • Union types or mixed-type arrays
  • Named types for nested objects
  • Production types without a manual review

For optional fields, unions and named nested types, use a generator that accepts multiple samples (such as quicktype) and feed it several diverse records. Always review generated types and add optional markers and unions your data actually needs.

Frequently Asked Questions

Why is every field required?
Because the tool infers from a single sample, it cannot tell which fields are sometimes absent. Everything present in your sample is typed as required. Add the optional marker by hand for fields that may be missing.
Can it detect optional or union types?
No. Optionals and unions only become visible across multiple, varied samples — a field missing from some, or a value with different types. From one sample, the tool types each field exactly as it appears.
How are arrays typed?
From the first element. So an array of strings becomes string array, but a mixed array is typed only from its first item, and an empty array becomes an array of any. Check array types if your data varies.
What happens to a null value?
It becomes any, because a null on its own gives no information about the real type. If you know the intended type, set it by hand after generating.
Does it name nested objects?
No. Nested objects are typed inline as anonymous shapes rather than separate named interfaces. For larger structures you may want to extract and name them yourself.
Is the output valid TypeScript?
Yes — it produces a valid interface you can paste straight into your code. It is a correct starting type; refining optionals and unions is the part left to you.
How do I get better types?
Provide multiple, diverse JSON samples to a generator built for that, like quicktype. With several samples it can mark optional fields and infer unions, producing far more accurate types than a single sample allows.
Does it validate my JSON?
It parses the JSON to read it, so invalid JSON will fail rather than generate a type. A successful result means the sample was valid JSON.
Why is the interface named Root?
It uses a fixed top-level name. Rename it to something meaningful for your data — the name does not affect the types, only how you refer to the interface.
Can it generate types instead of interfaces?
It outputs an interface. You can convert it to a type alias by hand if you prefer, since the two are largely interchangeable for object shapes in TypeScript.
Is my JSON uploaded anywhere?
No. The generation happens entirely in your browser. Nothing is sent to a server, so real payloads stay on your device.
Does it handle deeply nested JSON?
Yes, it recurses into nested objects and arrays. Very deep or large structures produce correspondingly large inline types, which you may want to break into named interfaces by hand.

References

Infers a TypeScript interface by reading the types in one JSON sample; honest that single-sample inference makes every field required and cannot detect optional or union types.

PopularHot

JSON Formatter

JSON Formatter for developers — instant, offline-style and privacy-safe.

DeveloperOpen Tool
Popular

JSON Validator

JSON Validator for developers — instant, offline-style and privacy-safe.

DeveloperOpen Tool
Popular

Base64 Encoder

Base64 Encoder for developers — instant, offline-style and privacy-safe.

DeveloperOpen Tool
Popular

Hash Generator

Fast, free Hash Generator that runs entirely client-side in your browser.

DeveloperOpen Tool
Popular

UUID Generator

Fast, free UUID Generator that runs entirely client-side in your browser.

DeveloperOpen Tool
Trending

CSS Minifier

Fast, free CSS Minifier that runs entirely client-side in your browser.

DeveloperOpen Tool

Ready to try the JSON to TypeScript?

It is free, private and runs entirely in your browser — no sign-up, no uploads, no limits.