JSON to types API

Generate TypeScript interfaces, Zod schemas, JSON Schema 2020-12, Go structs, Python dataclasses or Pydantic models from one or more JSON samples.

POSThttps://apibox.io.vn/v1/json-to-types
Developer utilities▶ Try it online

Paste a JSON sample in json (or several in samples) and choose lang: typescript, zod, json-schema, go, python (dataclasses), pydantic (v2), a comma-separated list or all. Samples are merged field by field: a field missing from some objects becomes optional, mixed kinds become unions, null makes a field nullable, integers and decimals merge into a number, and a top-level array of objects is read as a list of records of one type.

Nested objects get their own named types from the key (array items are singularised: items → Item, addresses → Address), identical shapes share one type, and strings are tagged with a format when every sample matches: RFC 3339 date-time (→ time.Time, datetime, z.string().datetime()), date, time, UUID, e-mail, URL. With enums=true short string fields with repeated values become literal unions / enums. Keys that are not valid identifiers are quoted (TypeScript, Zod), tagged (Go json:"…") or aliased (Pydantic Field(alias=…)).

The generator is our own (no quicktype): up to 100 samples, 200,000 values and 64 levels of nesting. code holds the first language, output every language requested. Python output uses X | None syntax (Python 3.10+).

Parameters

NameInTypeRequiredDefault
jsonbodyobjectnoOne JSON sample (any JSON value, or a JSON string).
samplesbodyarraynoSeveral samples of the same type (up to 100), merged.
langbodystringnotypescripttypescript, zod, json-schema, go, python, pydantic, a comma list or all.
namebodystringnoRootName of the root type.
detect_datesbodybooleannotrueDetect date-time / date / time strings.
enumsbodybooleannofalseTurn short repeated string values into literal unions / enums.

Example

curl -X POST "https://apibox.io.vn/v1/json-to-types" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"json":{"id":1,"name":"An","created_at":"2026-11-10T08:30:00Z","tags":["vip"],"address":{"city":"Hà Nội","zip":null}},"lang":"typescript","name":"Customer"}'

Response

{
  "root": "Customer",
  "samples": 1,
  "types": [
    "Customer",
    "Address"
  ],
  "languages": [
    "typescript"
  ],
  "code": "export interface Customer {\n  id: number;\n  name: string;\n  /** format: date-time */\n  created_at: string;\n  tags: string[];\n  address: Address;\n}\n\nexport interface Address {\n  city: string;\n  zip: null;\n}\n",
  "output": {
    "typescript": "(same as code)"
  }
}

Use cases

  • Type an API response before writing the client
  • Create a Zod or Pydantic validator from example payloads
  • Write a JSON Schema for a webhook from real events
  • Generate Go structs for a third-party JSON API

FAQ

How do I mark fields as optional?

Send several samples in "samples": fields absent from some of them become optional (?, .optional(), pointer + omitempty, = None).

Which Zod version is targeted?

Zod 3 syntax (z.string().datetime(), .email(), .uuid()), which also works in Zod 4.

Are dates detected?

Yes, strings that are RFC 3339 date-times or YYYY-MM-DD dates in every sample; detect_dates=false keeps them as plain strings.

Related APIs

Start with 1,000 free requests every month. Get free API key →