Last updated:
JSON Schema to TypeScript, Zod, Pydantic and Go
Convert JSON Schema to TypeScript interfaces, Zod, Pydantic, Go structs or GraphQL, or turn TypeScript, GraphQL or a JSON example into JSON Schema. Paste the source on the left and the output appears on the right.
How This Works
All conversions use JSON Schema as an intermediate representation. Your JSON Schema input is first read into a JSON Schema, then converted to TypeScript Interface. What a format can't express is listed under the output. All processing happens in your browser — your schemas are never sent to a server.
What this tool does
A modern application stack rarely settles on a single schema format. The API contract lives in OpenAPI, the frontend types live in TypeScript, the runtime validation lives in Zod or Pydantic, the analytics pipeline ingests JSON Schema, and somewhere along the way somebody added a GraphQL gateway. Each of these wants the same shape — a User has an id, an email, a role enum, an optional age — but each demands its own dialect, and keeping six dialects in sync by hand is the kind of work that sounds tractable until the third schema change in a week. This converter does the translation for you.
The architecture is hub-and-spoke. Every input is parsed into JSON Schema as a canonical intermediate, then JSON Schema is emitted in whichever target language you chose. That means adding support for a new format is two converters (in and out) instead of N×N. It also means the conversion is bounded by what JSON Schema can express — Zod refinements, Pydantic validators, and TypeScript conditional types are below that boundary and do not survive the trip. The conversion runs entirely in your browser, so the schemas you paste, with their customer field names or unreleased product domains, never leave it. We record which formats you converted between, with counts such as the number of properties, never the schema.
When to use the Schema Converter
Adopting Zod on a TypeScript frontend that already has JSON Schema. Your backend's payloads are described in JSON Schema; the frontend has been using any at the API boundary. Convert the schemas to Zod, drop the resulting validators into the fetch layer, and pick up runtime validation without rewriting your types.
Migrating a backend from Python to Go. Pydantic models are a structural definition of every payload your service handles, and Pydantic can export them as JSON Schema (model_json_schema()). Convert that JSON Schema to Go structs and you have starting types for the new service in the right shape. The converter adds JSON tags and uses pointer types for optional fields, which removes most of the manual translation.
Introducing GraphQL on top of a REST API. Your existing JSON Schemas describe the shape of every resource. Convert them to GraphQL SDL as a starting point for your schema-first design. The converter writes non-null markers, list wrappers, enums, and unions of object types; values GraphQL can't type, such as maps and mixed unions, use a JSON scalar it declares, and the notes under the output list each one. Interfaces and custom scalars are yours to add.
Prototyping a typed model from a JSON example. An external API returns JSON with no schema documentation. Paste a representative response, choose your target format, and you have a working type definition in seconds. The inference detects dates, date-times, emails, URLs, UUIDs and IPv4 addresses (only when the value really is one), so the generated types reflect more than the structural shape.
Converters for one pair of formats
These pages open the converter on one pair, with worked examples of its output for that pair and the mistakes that come with it:
- JSON to TypeScript Converter
- JSON to Go Struct Converter
- JSON Schema to Zod Converter
- JSON to Pydantic Converter
Walkthrough with a real example
Start with a JSON Schema for an application user, with formats and bounds on the fields that need them, and a manager who is another user:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "User",
"type": "object",
"required": ["id", "email", "displayName", "role", "tags", "createdAt"],
"properties": {
"id": { "type": "string", "format": "uuid" },
"email": { "type": "string", "format": "email" },
"displayName": { "type": "string", "minLength": 1, "maxLength": 80 },
"role": { "type": "string", "enum": ["admin", "editor", "viewer"] },
"age": { "type": "integer", "minimum": 0, "maximum": 130 },
"tags": { "type": "array", "items": { "type": "string" } },
"createdAt": { "type": "string", "format": "date-time" },
"manager": { "$ref": "#" }
}
}
Paste it into the converter with JSON Schema as the source and Zod as the target. The chained checks map one-to-one to the JSON Schema constraints: format: "uuid" becomes .uuid(), minLength becomes .min(), and the date-time accepts an offset such as +01:00, as JSON Schema does. The age field is optional because it's absent from the required array. Because manager refers back to the user itself, the schema is wrapped in z.lazy() and given an explicit User type, which TypeScript needs for a recursive schema:
import { z } from "zod";
export interface User {
id: string;
email: string;
displayName: string;
role: "admin" | "editor" | "viewer";
age?: number;
tags: string[];
createdAt: string;
manager?: User;
}
export const userSchema: z.ZodType<User> = z.lazy(() =>
z.object({
id: z.string().uuid(),
email: z.string().email(),
displayName: z.string().min(1).max(80),
role: z.enum(["admin", "editor", "viewer"]),
age: z.number().int().min(0).max(130).optional(),
tags: z.array(z.string()),
createdAt: z.string().datetime({ offset: true }),
manager: z.lazy(() => userSchema).optional(),
})
);
Switch to Python Pydantic. The same JSON Schema produces a BaseModel with the constraints in Field(), snake_case field names with an alias back to the JSON name, and populate_by_name so either name works. The uuid and date-time formats become uuid.UUID and datetime.datetime; email stays a plain str, since Pydantic's EmailStr needs an extra package. The self-reference is resolved by model_rebuild() at the end:
from __future__ import annotations
import datetime
import uuid
from typing import List, Literal, Optional
from pydantic import BaseModel, ConfigDict, Field
class User(BaseModel):
model_config = ConfigDict(populate_by_name=True)
id: uuid.UUID
email: str
display_name: str = Field(alias="displayName", min_length=1, max_length=80)
role: Literal["admin", "editor", "viewer"]
age: Optional[int] = Field(default=None, ge=0, le=130)
tags: List[str]
created_at: datetime.datetime = Field(alias="createdAt")
manager: Optional[User] = None
User.model_rebuild()
Both outputs derive from the same JSON Schema, so tightening maxLength on displayName carries the new limit into both on the next conversion. The schema's title names the root type; without one it's called Root.
TypeScript works as a source too. The converter reads it with the TypeScript compiler's own parser, and JSDoc tags carry what TypeScript can't say: @format, @minimum, @maximum, @minLength, @maxLength, @pattern, and @asType integer for a number that must be whole. This category refers to itself twice:
/** A product category, which can hold subcategories. */
export interface Category {
/** @asType integer */
id: number;
name: string;
parent?: Category;
children: Category[];
/** @format uri */
url?: string;
}
Converted to Go, the optional parent becomes a pointer with omitempty, the children a slice, and the interface's comment the struct's doc comment:
package models
// Category A product category, which can hold subcategories.
type Category struct {
ID int64 `json:"id"`
Name string `json:"name"`
Parent *Category `json:"parent,omitempty"`
Children []Category `json:"children"`
URL *string `json:"url,omitempty"`
} Schema format concepts you should know
Static type systems versus runtime validators. TypeScript interfaces, GraphQL types, and Go structs are static — they exist at compile time and disappear at runtime. JSON Schema, Zod, and Pydantic are runtime — they validate actual values as the program runs. The two solve different problems: static types catch bugs in your code, runtime validators catch bugs in the data crossing your trust boundary. Most production systems need both, which is why the conversion direction matters.
Validation versus typing. A TypeScript interface says "I expect this shape." A Zod schema says "I will reject this if it does not have this shape." Converting from a static type to a runtime validator is mostly safe; converting the other direction loses the validation logic. When in doubt, treat the validator as the source of truth and let the static type be derived from it (the z.infer pattern).
Format-specific features that do not round-trip. Zod's .transform() and .refine() let you express arbitrary JavaScript predicates that JSON Schema cannot represent. Pydantic field_validators and root_validators have the same property. TypeScript conditional types, mapped types, and template literal types are similarly unrepresentable. GraphQL interfaces and unions translate awkwardly into JSON Schema oneOf. Be deliberate about which format owns the source of truth.
Nullability and optionality. These are not the same. A property can be required-and-nullable (the field must be present, and its value may be null), required-and-non-nullable (must be present, must have a real value), optional-and-nullable, or optional-and-non-nullable. JSON Schema expresses both axes; TypeScript merges them when you write x?: string | null; Pydantic distinguishes them via Optional versus a default value. The converter keeps both axes where the target can: a nullable type ("type": ["string", "null"], a oneOf with null, or OpenAPI 3.0's nullable: true) becomes | null in TypeScript, .nullable() in Zod, Optional[...] in Pydantic, a pointer in Go and a type without ! in GraphQL, while optional fields get ?, .optional() and omitempty. Two targets merge the axes: Pydantic writes every optional field as Optional[...] = None, so it also accepts null, and GraphQL has only nullability, so optional fields lose their ! too.
Discriminated unions. A union of object types with a shared discriminator field (type: "circle" versus type: "square") is a foundational pattern in TypeScript, supported natively in Zod via z.discriminatedUnion(), and modeled in JSON Schema with oneOf plus a const on the discriminator. GraphQL has unions but no discriminator field — the type is implicit in the response. The converter's Zod output uses z.discriminatedUnion() when every option of a oneOf is an object with the same required property set to a different constant; TypeScript narrows the plain union of those interfaces on its own. Its GraphQL output writes a union when every option is an object type.
Naming conventions. JavaScript and TypeScript use camelCase. Python uses snake_case. Go uses PascalCase for exported names. The converter respects each ecosystem's convention and emits aliases or tags where needed (Pydantic alias=, Go json:"") so the converted models can still parse data from a system that uses a different convention.
Common mistakes
Expecting Zod refinements to survive a conversion. A .refine(val => val.startsWith("acct_")) is a JavaScript predicate. JSON Schema cannot encode it. After conversion you will need to re-add it as a custom validator in the target format.
Treating GraphQL Int as a 64-bit type. The GraphQL spec defines Int as a 32-bit signed integer. If your data has values above 2,147,483,647, use a custom Long or BigInt scalar; the default Int will overflow silently. The converter maps integers to Int and lists, in the notes under the output, every field whose format is int64 or whose bounds go past 32 bits.
Assuming TypeScript interfaces validate at runtime. TypeScript types are erased before the code runs. A function that takes a User argument will happily accept any object at runtime if the caller cast it. If you need the boundary check, convert the interface to Zod and use the Zod schema to parse the input.
Missing nullable handling differences across targets. GraphQL fields are nullable by default and require an explicit non-null marker. Pydantic fields are required by default and need Optional for nullability. TypeScript splits the two with ? and | null. Mismatching the source's intent against the target's defaults produces converted code that compiles but lies about which fields are required.
Forgetting to apply field-level validators after generating Pydantic models. The converter emits the structural model with constraints expressible in Field(). If the original system had complex validators (cross-field invariants, format checks beyond the standard set), you need to add those back after generation. Treat the output as a starting point, not as a drop-in replacement.
FAQ
Does the converter support allOf, oneOf, and anyOf composition?
Yes. An allOf of objects (inline or through $ref) is merged into one object in every output, with the properties and required lists combined. oneOf and anyOf become unions: A | B in TypeScript, z.union in Zod (or z.discriminatedUnion when every option is an object with the same required property set to a different constant), Union in Pydantic, and a GraphQL union when every option is an object type. Go has no union types, so there they become any, and the notes under the output say so. An allOf that mixes objects with other types becomes an intersection in TypeScript and Zod, and an untyped value in the other outputs, with a note.
What happens with $ref pointers that resolve outside the pasted schema?
References inside the document resolve: to $defs, definitions, components.schemas, the root (#), any other JSON pointer, or an $anchor. A reference to another file, such as shared/types.json#/Product, can't be followed in the browser: it becomes an untyped value (unknown, Any, any), and the notes under the output name it. Paste the referenced schema into $defs, or convert the bundled schema your build produces.
Can it handle circular references between schemas?
Yes. Definitions come out in dependency order, so each one follows the definitions it uses. When definitions refer to each other in a cycle, or a definition refers to itself, the Zod output wraps them in z.lazy() with an explicit TypeScript type (so it compiles under --strict), the Pydantic output starts with from __future__ import annotations and calls model_rebuild() on every model, and the Go output holds the structs in the cycle by pointer. TypeScript and GraphQL need nothing extra.
Will a round-trip from one format back to itself be lossless?
Not always. Going TypeScript → JSON Schema → TypeScript keeps property types, literal unions, arrays, optional and readonly fields, and names: the root keeps its interface name, and inline nested objects come back as named interfaces such as OrderCustomer. extends comes back as the merged properties, and generics, mapped, conditional and template literal types have no JSON Schema form. Zod refinements and Pydantic validators live below the schema level and can't pass through the JSON Schema in the middle either.
Does the generated code compile?
That's what the converter's tests check. Every example on this page and a corpus of schemas (nested and recursive types, enums of every kind, nullable unions, odd property names, descriptions with */ and """) are converted to every format and compiled: TypeScript with tsc --strict, Zod 3 and Zod 4, Pydantic 2 on Python 3.9, Go with go vet and gofmt, and GraphQL with graphql-js. Each output must also accept sample data the schema accepts, and the Zod output must reject data the schema rejects.
What is the practical size limit for a schema being converted?
There's no fixed limit: the conversion runs in your browser, so a large schema only takes longer. The first conversion from TypeScript downloads the TypeScript compiler (about 1 MB compressed), and the first from GraphQL downloads graphql-js's parser (about 9 KB); after that they convert as you type. For a very large output, copy or download it rather than scrolling through it here.
Related tools and guides
- JSON Schema Validator — once you have a JSON Schema (whether you wrote it directly or generated it via this converter), validate real payloads against it to confirm the schema captures the actual data shape.
- OpenAPI Editor — when the JSON Schema you converted lives inside an OpenAPI document, edit and preview the surrounding spec without leaving the browser.
- YAML to JSON Converter — when the schema or example you want to convert is written in YAML, convert it to JSON first; values such as
version: 1.0that change type on the way are listed by line. - Mock Data Generator — generate sample payloads that conform to a converted schema, useful for tests, fixtures, and stubbing out a backend during frontend development.
- Complete Guide to JSON Schema — covers the JSON Schema vocabulary the converter uses as its intermediate representation, including composition, conditional schemas, and reuse patterns.
- API Versioning Guide — when you regenerate types from an updated schema, every consumer feels the change; this guide covers the patterns for evolving them safely.