onlinetools.dev

JSON → TypeScript Types

Infer TypeScript interfaces from a JSON sample instantly

Runs locally
loading…
About this tool

Paste a JSON sample — an API response, a config file — and get a TypeScript interface inferred from it: nested objects become nested types, arrays get element types (with unions for mixed contents), and keys that are not valid identifiers are quoted properly.

Generated types are a starting point, not a contract: inference sees one sample, so a field that happens to be null in your example types as null, and optional fields that were absent are simply unknown to it. The output is deliberately plain — no decorators, no runtime validation — so you can paste it anywhere and refine.

For fields that vary between requests, run a second sample through and merge by hand, or graduate to schema-first tooling (OpenAPI, zod) once the shape stabilizes. For the daily "I just need a type for this response" moment, one paste is enough.

Frequently asked questions

Why is my nullable field typed as just null?
Inference sees only the sample you pasted. If the field was null there, null is all it can know. Change it to string | null (or whatever the real type is) after generation — or paste a sample where the field is populated.
How are optional fields handled?
They are not detected — a single sample cannot distinguish "always present" from "present this time". Fields absent from the sample are absent from the type. Mark fields optional (name?:) manually where you know the API omits them.
What do mixed-type arrays produce?
A union: [1, "a"] infers (number | string)[]. Empty arrays infer unknown[] since there is no element to inspect — replace with the real element type when you know it.
Should I use inferred types or a schema library like zod?
Inferred interfaces are compile-time only — they do not validate anything at runtime. For internal tools and quick typing they are perfect; for untrusted input at runtime, define a zod/valibot schema and derive the static type from it instead.
Related tools