# JSON to TypeScript

Turn a JSON sample into TypeScript interfaces or a JSON Schema, with optional and nullable kept apart. Nothing you paste is uploaded.

Canonical page: https://filetity.com/json-to-typescript

## Capabilities

- Free: Yes, with no watermark and no page limit.
- Account required: No. There is no account system.
- Processed on device: Yes. The file is read by your browser and never uploaded. There is no server to send it to.
- Formats: Any valid JSON in. TypeScript interfaces out, or a JSON Schema draft 2020-12 document.
- Limits: It can only describe what your sample contains. A field that is always null in the sample is typed null, because that is the one thing the sample actually said.
- Mobile: Yes, on any modern mobile browser. Large files are limited by the memory the phone gives the browser.
- Offline: Yes, once the page has loaded. The tool keeps working with no network connection.

## Questions

### What is the difference between a? and | null in the output?

A question mark means the key was missing from some records in your sample. Writing null means the key was there and held null. They are different claims about your data and neither is silently turned into the other, because only one of them is something the sample demonstrated.

### Why is my array of records one interface instead of a union?

Because that is what a list of records is. If one entry has a nickname and the others do not, the useful answer is a single interface with an optional nickname, not a union of two shapes you then have to narrow between on every access. Every element is folded into one shape and one-sided keys become optional.

### What do I get for an empty array?

It becomes unknown, not any. An empty array carries no information about what belongs in it, and typing it any would quietly switch the type checker off for everything downstream of it, which is the opposite of why you generated types.

### Are numbers ever typed as integers?

Not in the JSON Schema, no. A sample containing only whole numbers does not prove the field is an integer, and guessing produces a schema that rejects valid data the first time somebody sends a decimal. Every number is typed as a number, which is what the sample supports.

### Do nested objects get their own interfaces?

Yes, named after the key they sit under, so an address inside a user becomes an Address interface. Inlining everything produces a two hundred line type nobody can read or reuse, and a name that collides with one already used gets its parent's name in front of it.

## Related tools

- [JSON Formatter and Validator](https://filetity.com/json-formatter): Format, beautify, validate and read JSON, and find the line that broke it.
- [JSON to YAML](https://filetity.com/json-to-yaml): Convert JSON to readable YAML, with no folded lines.
