BrainCoder
DeveloperNothing uploaded

JSON to TypeScript

A first draft of the types, from one JSON sample

Free forever — no sign-up, nothing uploaded. Files never leave your device.

braincoder.app/use/json-to-typescript

JSON to TypeScript

A first draft of the types, from one JSON sample

Drop your file here

or browse from your device

Browse files

document.pdf

1.2 MB

report.pdf

860 KB

100% private

Nothing is uploaded — everything runs in your browser.

Free forever

No account or payment required.

No sign-up

Open the tool and start using it right away.

Local processing

Processing time depends on your input and device.

About this tool

Paste one JSON sample and get one export interface for the root plus an interface for every nested object, with array elements merged and JSON null kept as a required null. Every generated name is checked for uniqueness and resolution before the result is called Generated. Nothing is uploaded.

Type inference from a sample is a small job that most converters overstate. This one reads exactly the JSON you paste and nothing else: the root object becomes one export interface, and every object nested inside it becomes its own named interface, named for the path that reached it — User, then UserProfile, then UserProfileAddress — so the output is a set of flat declarations you can read top to bottom instead of a wall of inline nested types. The old version of this page finished every object document with export type User = User;, which is TS2300 Duplicate identifier and does not compile at all. There is no such line here, and nothing is labelled Generated until the emitted names have been checked for duplicates and for resolution.

The decisions it makes are the ones a sample can actually support, and they are stated rather than buried. An array of objects is merged into a single element shape: a key missing from at least one element is marked optional, and keys whose shapes disagree become a union of what was really seen, never any. A JSON null is a value rather than a hole, so it stays required and renders as null — an earlier version made it any, which quietly turned a required field into an optional one. Every number is number; a date, a UUID or an enum that arrives as a string reads as string, because nothing in a sample can tell those apart. An empty object is Record<string, never> and an empty array is unknown[], since a member-less interface would accept every object you could pass it. A root name that is a TypeScript keyword, or a built-in type such as Record that an interface would shadow, falls back to Root and the page says so out loud instead of substituting quietly.

What it deliberately does not do is worth the same space as what it does. There is no JSDoc on each field, because a comment guessed from one value is a comment that will be wrong. There is no enums, no generics, no type-alias mode, no converters, and no date library. A key your sample does not contain is not marked optional, because the sample cannot know whether the field is absent, null, or simply not in the response you happened to paste. Copy the result into a .ts file and it compiles as written; widen the sample, or edit the interface, before you rely on it.

Input is capped before anything is parsed — 200,000 characters of pasted text, 64 nesting levels, 200,000 values in the document, and 400,000 characters of generated code, since an array of objects can imply more fields than the input has characters — and each cap is refused with the real numbers rather than silently truncating. Your JSON is read in this tab. Nothing is uploaded, and no request is made with your data at all.

Key features

Everything you get with JSON to TypeScript — no premium upsell.

One export interface for the root object and one named interface per nested object, named for the path that reached it — User, UserProfile, UserProfileAddress — with no inline nested types to unfold

The output is checked before it is called Generated: duplicate or unresolvable type names are reported as a stated problem instead of a green badge on code that would not compile

An array of objects is merged into one element shape; a key missing from any element is marked optional, and shapes that disagree become a union of what was actually seen

A JSON null is a value, so it stays required and renders as null — never any, and never an optional marker

Every number is number, and a date, UUID or enum that arrives as a string reads as string; nothing is guessed beyond what the sample shows

An empty object is Record<string, never> and an empty array is unknown[], because a member-less interface would accept every object

A root name that is a TypeScript keyword or a built-in type such as Record falls back to Root, and the page names the substitution and the reason

Keys that are not legal identifiers are sanitized and de-duplicated deterministically, so two keys that both clean to a_b become a_b and a_b_2 rather than a duplicate member

No JSDoc comments, no enums, no generics, no converters and no type-alias mode: the output is interfaces, and arrays are written as array types

Caps of 200,000 characters of input, 64 nesting levels, 200,000 values and 400,000 characters of generated code, each refused with its real numbers before anything is emitted

An interface count, a field count and a character count on screen, plus Copy, a .ts download named for the root type, Load sample and Clear

Runs entirely in this tab — your JSON is never uploaded and no request is made with it

How to use JSON to TypeScript

Follow the steps below to use the tool.

  1. 1

    Paste one JSON sample

    Paste a single object, array or value into the box, or use Load sample. Nothing is pre-filled, so nothing on screen can be confused with your data. One response from one endpoint is a sample, not a schema: the types describe what this document contains.

  2. 2

    Name the root type

    Type the name you want in the root box. A name that is a TypeScript keyword, or a built-in an interface would shadow such as Record, becomes Root and the page says which name it used and why. Renaming re-emits the types without re-reading the JSON.

  3. 3

    Read the counts, then read the code

    The panel under the output gives the interface count, the field count and the character count. Then read the code: optional markers mean a key was missing from at least one element of a merged array, a union means two shapes were really seen, and a field your sample never contained is not marked optional at all.

  4. 4

    Copy or download, then tighten it

    Copy puts the exact text on the clipboard; Download writes the same bytes to a file named for the root type. The code compiles as written — then edit it: add the fields the sample was missing, narrow the strings that are really dates, IDs or enums.

Still free, still private — your files never leave your device.

Launch JSON to TypeScript

Frequently asked questions

Quick answers before you launch the tool.