fileview.dev

Generate TypeScript from JSON

Paste a JSON payload and get TypeScript interfaces describing it — with nested objects hoisted into named types rather than inlined — plus Go, Rust, Python and JSON Schema from the same inference.

Generate types from JSON

What the inference does

It walks a sample and describes what it finds: types for each field, optionality where a key is missing from some elements of an array, and unions where a field holds more than one type across samples. Nested objects become named interfaces rather than being inlined, which is the difference between output you can use and output you have to rewrite.

{
  "id": 1,
  "name": "Ada",
  "address": { "city": "London", "postcode": "W1J 9BW" },
  "tags": ["engineer", "mathematician"]
}
Input
interface Address {
  city: string;
  postcode: string;
}

interface Root {
  id: number;
  name: string;
  address: Address;
  tags: string[];
}
Output

Other targets

What inference cannot know

It describes the sample, not the contract. A field that happens to be present in your one example is marked required; a field that is null in the sample cannot be typed beyond null; and a date is a string, because in JSON it is. Treat the output as a first draft that saves you the typing, not as a specification.

Generate types from JSON

Questions

How do I convert JSON to a TypeScript interface?

Open the JSON in fileviewer.dev and run "Generate TypeScript types" from the command palette. The types are inferred from the document and downloaded as a .ts file, with nested objects hoisted into their own named interfaces.

Can it generate Go structs or Python types too?

Yes. The same inference pass drives TypeScript interfaces, Go structs with json tags, Rust structs with serde derives, Python dataclasses, and a JSON Schema.

Are the generated types accurate?

They describe the sample you gave it, which is not the same as describing your API. Every key present is marked required, a null field cannot be typed further, and a date is a string. Use a large, varied sample and treat the result as a starting point.

Is my JSON uploaded to generate the types?

No. Inference and code generation run entirely in your browser — useful, since the payloads people most want to type are usually from an internal API.