# JSON to TypeScript Types

> Paste JSON, get TypeScript interfaces, type aliases, Zod schemas, or Valibot schemas. Updates as you type.

- URL: https://generate.now/json-to-types
- Category: data
- Price: free, no account required
- AI-powered: no
- Last updated: 2026-08-27

## What it does

Convert any JSON sample into a TypeScript type definition or runtime schema. Toggle between interface, type alias, Zod, and Valibot output. Configure root name, optional fields, readonly modifiers, and how to handle nulls. Powered by quicktype.

## When to use it

- Generate types for a third-party API you only have a sample response from
- Bootstrap a Zod schema from a JSON fixture
- Convert an inherited JSON blob into proper TypeScript before refactoring
- Add runtime validation to a route that previously trusted unknown input

## Examples

### { "id": 1, "name": "Alex", "active": true }

```
interface Root {
  id: number;
  name: string;
  active: boolean;
}
```

Basic interface inferred from a single sample.

### { "items": [{ "id": "a" }, { "id": "b", "label": "B" }] }

```
interface Root {
  items: Item[];
}
interface Item {
  id: string;
  label?: string;
}
```

Array items are merged and fields present in only some objects become optional.

### { "id": 1, "name": "Alex" }  // Zod output

```
z.object({ id: z.number(), name: z.string() })
```

Same shape as a Zod schema for runtime validation.

## Frequently asked questions

### How does the tool decide whether a field is optional?

For an array of objects, any field that's missing from at least one object becomes optional. For a single object, every field is required by default. You can toggle the 'mark optional' option to soften this.

### What's the difference between an interface and a type alias?

For object shapes, they're nearly interchangeable. Interfaces can be augmented via declaration merging; type aliases support unions and primitives. The tool picks interface by default for object-shaped JSON.

### When should I use Zod or Valibot instead of TypeScript types?

Use plain TS types when the data is already trusted (e.g. you control the producer). Use Zod or Valibot at the trust boundary — incoming HTTP requests, external API responses, env vars — where you want runtime validation to back the static type.

### Why is a number sometimes typed as 'number' and sometimes as a literal?

If every sample shows the same literal value, the tool can narrow to that literal — useful for status fields like 'success' or 'error'. By default it widens to the broader primitive; you can override with the 'narrow literals' option.

### How do nulls become 'unknown'?

When a field is null in the sample, the tool can't tell what its non-null type is. The default is to emit T | null where T is best-guessed, but you can switch to unknown to be more strict.

### Does it support deeply nested objects?

Yes. Each nested object becomes its own type, named after the field. You can rename types in the output panel.

## References

- [RFC 8259: The JSON Data Interchange Format](https://datatracker.ietf.org/doc/html/rfc8259) — IETF. The normative definition of JSON, including its value types and encoding rules.
- [TypeScript everyday types](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html) — Microsoft. Reference for the interface and type-alias forms this tool emits.
- [Zod](https://zod.dev) — Zod. Documentation for the runtime schema output option, including inference to static types.
- [quicktype](https://quicktype.io) — quicktype. The type-inference engine used to derive types from a JSON sample.

## Related tools

- [Regex Generator](https://generate.now/regex): Describe what you want to match in plain English. Get a regex pattern with a live test panel and a token-by-token breakdown.
- [UUID Generator](https://generate.now/uuid): Generate UUIDs (v1, v4, v7, v8) in bulk, with format options and a validator. Cryptographically random by default.
- [Lorem Ipsum Generator](https://generate.now/lorem): Generate placeholder text in seconds. Classic Latin or modern variants — corporate, hipster, bacon. By paragraphs, sentences, or words.
