JSON → TypeScript

Paste a JSON sample to infer TypeScript interfaces. Differing types across array elements become unions; missing properties become optional. The input must be an object or an array of objects. Use it to sketch types from an API response before writing them by hand. Inference runs entirely in the browser; the sample is never uploaded.

Press GenerateInterfaces are derived from the JSON you paste

Runs in this tab · nothing is uploaded · Verify in 10 seconds →

What the JSON → TypeScript generator does

This generator turns a JSON sample (an API response, a config file, a fixture) into TypeScript interfaces you can paste straight into your code. Nested objects become their own named interfaces, and arrays of objects are merged into a single element type.

How the JSON → TypeScript generator works

The JSON is parsed with your browser's JSON.parse, then the json-to-ts library walks the value and emits one interface per distinct object shape, starting from the root name you choose. Every step runs locally in this tab; the sample never leaves your device.

Limits

Input must be an object or an array of objects.

~/faq

Frequently asked questions

How are arrays of objects typed?

All elements of an array are merged into one interface. A property present in every element keeps its type, a property missing from some elements becomes optional (marked with ?), and the same property with different types across elements becomes a union like number | string. That is why a sessions array whose items differ produces an interface with optional members.

Why are some properties optional when my API always sends them?

The generator only sees the sample you paste. If a property is absent from one array element in the sample, it is typed as optional. Feed it a sample where every element carries the property, or remove the ? by hand when you know the API guarantees it.

Why can't I generate types for a plain string or number?

Interfaces describe object shapes. The underlying library accepts a JSON object or an array of objects; a bare string, number, boolean or mixed array has no members to describe, so the tool shows an error instead. For those, a plain type alias like type Root = string is all you need.

Is null handled?

A property that is null in the sample is typed as null, because null is all the sample proves. If the field is really a nullable string, widen it to string | null yourself.

Does my JSON get uploaded?

No. Parsing and interface generation run entirely in this tab | LocalFirstTools has no server that receives your sample, which matters when it comes from a production API response.