# JSON to TypeScript & Zod

> Generate TypeScript interfaces, type aliases or a Zod schema from sample JSON. Merges array items and marks missing keys optional.

Category: Data & JSON. This tool runs in your browser.

Open the interactive tool: https://www.devkult.com/tools/json/json-to-typescript

## FAQ

### How are arrays of objects turned into a type?

Every element is merged into one shape. A key missing from some elements becomes optional (`key?:`), and a key whose type differs between elements becomes a union such as `string | number`. Paste several representative records for the most accurate result.

### What happens to null values?

A field that is null in every sample is typed as `null`. If another sample has a value, the field becomes a union like `string | null` — in Zod, `z.string().nullable()`. Include a record where the field is filled in to get the useful type.

### Should I use interfaces or type aliases?

For object shapes they are interchangeable in almost all code. Interfaces can be extended and merged by declaration; type aliases can also express unions and mapped types. Follow whatever your codebase already uses.

### Why generate a Zod schema instead of plain types?

TypeScript types disappear at runtime, so they can't check that an API really returned what you expect. A Zod schema validates the data when it arrives and gives you the same static type through `z.infer`.

### Is my JSON uploaded anywhere?

No. Type inference runs in your browser; the JSON never leaves your machine.

## More Data & JSON tools

- [JSON Diff & Compare](https://www.devkult.com/tools/json/json-diff.md): Compare two JSON documents structurally — added, removed, and changed values with exact paths, ignoring key order.
- [JSON Formatter](https://www.devkult.com/tools/json/json-formatter.md): Format and beautify JSON instantly with syntax highlighting.
- [JSON Validator](https://www.devkult.com/tools/json/json-validator.md): Validate JSON and get detailed error messages.
- [YAML ↔ JSON](https://www.devkult.com/tools/json/yaml-json-converter.md): Convert between YAML and JSON formats seamlessly.
- [CSV ↔ JSON ↔ SQL](https://www.devkult.com/tools/json/data-converter.md): Transform data between CSV, JSON, and SQL Insert formats.
- [SQL Formatter](https://www.devkult.com/tools/json/sql-formatter.md): Beautify and format your SQL queries for better readability.