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.
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
| Name | In | Type | Required | Default | |
|---|---|---|---|---|---|
json | body | object | no | One JSON sample (any JSON value, or a JSON string). | |
samples | body | array | no | Several samples of the same type (up to 100), merged. | |
lang | body | string | no | typescript | typescript, zod, json-schema, go, python, pydantic, a comma list or all. |
name | body | string | no | Root | Name of the root type. |
detect_dates | body | boolean | no | true | Detect date-time / date / time strings. |
enums | body | boolean | no | false | Turn 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"}'const res = await fetch('https://apibox.io.vn/v1/json-to-types', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"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"
}),
});
const data = await res.json();
console.log(data);import requests
res = requests.post(
"https://apibox.io.vn/v1/json-to-types",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={"json": {"id": 1, "name": "An", "created_at": "2026-11-10T08:30:00Z", "tags": ["vip"], "address": {"city": "Hà Nội", "zip": None}}, "lang": "typescript", "name": "Customer"},
timeout=30,
)
print(res.json())<?php
$ch = curl_init('https://apibox.io.vn/v1/json-to-types');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_KEY', 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => '{"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 = curl_exec($ch);
print_r(json_decode($response, true));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
UUID Generator
Generate up to 1,000 UUID v4, time-ordered UUID v7, ULID, Nano ID or random hex IDs per request. Secure randomness, optional uppercase.
⏱Cron Expression Parser
Validate a cron expression and get its next run times in any timezone, with a plain-English description. Supports 5, 6 and 7-field cron syntax.
🕒Time & Timezone Converter
Get the current time in any timezone, convert between timezones and Unix timestamps (seconds or ms), with UTC offset and weekday for up to 30 zones.