# JSON to Types

> Paste JSON, get TypeScript, Zod, Pydantic, dataclass, and Go types.

Free JSON to type converter. Paste a JSON document and generate TypeScript interfaces, Zod schemas, Python Pydantic models or dataclasses, and Go structs. Optional fields are detected across array items, nulls become nullable, and nested objects get their own named types.

- Page: https://benchline.fabwaseem.com/t/json-to-types
- Runs: in the browser. Input stays on the device.
- Price: free, no account
- Input: A JSON document, the root type name, and the target languages.
- Output: Type definitions per target, plus warnings for ambiguous shapes.
- Keywords: json to typescript, json to zod, json to pydantic, json to go struct, json type generator
- Updated: 2026-10-18
- Built by: Waseem Anjum (https://fabwaseem.com)

## How to use it

1. **Paste your JSON.** Drop a JSON document into the editor, upload a .json file, or start from the sample.
2. **Pick the targets.** Toggle TypeScript, Zod, Pydantic, dataclass, and Go. Set the root type name.
3. **Copy the output.** Each target gets its own tab with copy and download buttons.

## Use it from an AI agent

MCP tool name: `convert_json_to_types`
MCP endpoint: https://benchline.fabwaseem.com/mcp (Streamable HTTP, no key)
HTTP: POST https://benchline.fabwaseem.com/api/v1/tools/json-to-types with the input as the JSON body
This call does not fetch anything. It runs on the arguments you send.

Infer types from a JSON document and generate TypeScript interfaces, Zod schemas, Python Pydantic models or dataclasses, and Go structs.

### Input schema

```json
{
  "type": "object",
  "properties": {
    "json": {
      "type": "string",
      "minLength": 1,
      "maxLength": 500000
    },
    "rootName": {
      "default": "Root",
      "type": "string",
      "maxLength": 80
    },
    "targets": {
      "default": [
        "typescript"
      ],
      "minItems": 1,
      "type": "array",
      "items": {
        "type": "string",
        "enum": [
          "typescript",
          "zod",
          "pydantic",
          "dataclass",
          "go"
        ]
      }
    }
  },
  "required": [
    "json",
    "rootName",
    "targets"
  ],
  "additionalProperties": false
}
```

### Example tools/call

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "convert_json_to_types",
    "arguments": {
      "json": "{}",
      "rootName": "Root",
      "targets": [
        "typescript"
      ]
    }
  }
}
```

Setup for Claude, Cursor, and VS Code: https://benchline.fabwaseem.com/mcp/guide

## Questions

### How are optional fields detected?

When the top level is an array of objects, a property missing from any item becomes optional. A property present everywhere stays required.

### What happens with null values?

Null becomes nullable in every target: `| null` in TypeScript, `.nullable()` in Zod, Optional in Python, and `any` in Go.

### How are empty arrays typed?

An empty array has no items to learn from, so it becomes unknown[] (or Any). Fill it in for a precise type; a warning is shown.

### What about very large numbers?

A number that does not fit in a JavaScript number still generates a number type, and a warning names the original digits. The type cannot store those digits exactly.

### Is my JSON sent anywhere?

No. Conversion runs entirely in the browser on this page.

## Related tools

- [JSON formatter](https://benchline.fabwaseem.com/t/json-formatter): Pretty-print, minify, and validate JSON, with the exact line and column when it fails.
- [JSON Schema](https://benchline.fabwaseem.com/t/json-schema-validate): Infer a schema from JSON, validate against one, and export TypeScript and Zod.
- [JSON YAML converter](https://benchline.fabwaseem.com/t/json-yaml-convert): Convert JSON, YAML, TOML, and XML in the browser, and keep the line number when a document fails.
- [JSON-LD schema generator](https://benchline.fabwaseem.com/t/schema-generator): Fill a form, get valid schema.org JSON-LD for Article, FAQ, Product, Organization, and more.
