Converter tool

JSON to TypeScript, Zod, Python, Go and Rust

Paste one or more JSON samples or a JSON Lines file and get TypeScript interfaces, Zod schemas, Python dataclasses, TypedDict or Pydantic models, Go structs or Rust serde structs, with optional and nullable fields worked out across the samples.

One JSON document, JSON Lines, or samples separated by a line holding only ---0 B / 5 MB

A field missing from some samples is optional; a field that was null is nullable. Digits alone make an integer and a decimal point or exponent makes a float. Samples are parsed by script in this tab and never uploaded, and nothing is kept in localStorage, sessionStorage or IndexedDB.

Preview

Output Preview

Paste JSON, JSON Lines or several samples separated by ---, and the types appear here as you type.

JSON to TypeScript, Zod, Python, Go and Rust

Operator: Abdulla Al Fahad. How tools are built and checked

The payload an endpoint really returns and the types a codebase declares for it drift apart without anyone noticing. A webhook gains a field, an export starts sending null for an address it used to leave out, and the interface written last spring still promises a string everywhere. Each language also asks a slightly different question about the same data: TypeScript needs to know whether a key can be absent, Go whether a zero value is acceptable, Rust whether to wrap the field in Option, and Pydantic what to call a key like first-name.

Paste the payloads you have and this page derives one set of declarations from all of them together: TypeScript, Zod, Python as Pydantic v2 models, dataclasses or TypedDict, Go structs or Rust serde structs. Switching the output language reuses the same reading of the samples, so every language gets the same answer about which fields may be missing, which may be null and what each nested object is called.

Key features

  • One reading of the samples, five outputs: TypeScript, Zod, Python, Go and Rust
  • Python as Pydantic v2 models, standard-library dataclasses or TypedDict
  • Absent-in-some-samples and null-in-some-samples tracked separately and written the way each language expresses them
  • Named types for nested objects, singular names for array elements, and one shared declaration when two shapes match exactly
  • Awkward keys handled per language: quoted TypeScript properties, Go json tags, serde renames, Pydantic aliases and the functional TypedDict form
  • Switches for interface or type, ?: or | undefined, readonly, exports, z.infer types, the Go package name, omitempty, pointers, Rust derives and None skipping
  • ISO 8601 date recognition that you can turn on

Sample layouts, number types and parse errors

Three layouts are understood. One JSON document. Several documents with a line of three dashes (---) on its own between them. Or JSON Lines, also called NDJSON: a block that fails as a single document is re-read one line at a time when its first non-empty line is complete JSON by itself and at least two lines have content. The text box takes up to 5 MB, typed or opened from a .json, .jsonl, .ndjson or .txt file, which can also be dragged onto the box. Text is decoded as UTF-8, a UTF-16 file is decoded when it begins with its BOM, and a spreadsheet, a .zip, a PDF or any other binary file is turned away with an explanation.

Numbers keep their written form. "seats": 5 counts as a whole number and "total": 49.0 as a decimal, and that difference decides int64 or float64 in Go, i64 or f64 in Rust and int or float in Python; TypeScript and Zod use number for both.

When something does not parse, the message names the sample or the JSON Lines line, gives the line and column counted across the whole text box, repeats the line and puts a caret under the character where reading stopped.

How it works

All five outputs are written from one model of the data, so switching tabs never changes which fields are optional or what a nested object is called; only the spelling changes. TypeScript writes a missing-in-some-samples key as coupon?: string, Zod as .optional(), Pydantic as a None default, Go as ,omitempty and Rust as Option<T> with skip_serializing_if.

Types that refer to each other are ordered for the language. TypeScript, Go and Rust start with the root and follow with nested types in the order they first appear, which reads top-down. Zod and Python need a schema or class defined before it is used, so they are written dependencies first and the root comes last.

Whole-number width is chosen per field: int64 and i64 by default, uint64 and u64 when a value lies between 2^63 and 2^64, and json.Number or serde_json::Number beyond that, so an oversized ID does not fail to decode in Go or Rust.

Names are handed out after all shapes are known, so matching shapes can be merged first; the section on names below gives the rules.

Common use cases

  • A frontend team gets a new endpoint before its OpenAPI description exists and needs interfaces for it today
  • Validating a partner's webhook events with Zod, built from events captured in the request logs
  • Loading a JSON Lines dump from a warehouse into Pydantic models for a cleaning script
  • Declaring Go structs for a third-party response that the vendor's SDK hands back as map[string]any
  • Giving a Rust command-line tool serde structs for the JSON in its cache or settings files

How to use this tool

  1. Gather two or three real payloads that differ: one with the optional parts present, one without them, one with nulls. Paste them with --- lines between them, or open or drop a .jsonl export.
  2. Replace Root with the name your code will use, such as Order or WebhookEvent.
  3. Pick the output tab and its switches. The declarations update as you type or change a setting.
  4. Check the summary line, which counts samples, named types, fields, optional fields and nullable fields, and read the amber notes.
  5. Take the output with the copy button or save it as a file, and place it in the module where that data enters your program.

Example

Two customer records from a billing API, with --- between them

{"id": 1, "email": "ana@example.com", "plan": {"name": "team", "seats": 5},
 "invoices": [{"number": "INV-104", "total": 49.0, "paid_at": null},
              {"number": "INV-097", "total": 49, "paid_at": "2026-02-01T10:00:00Z"}]}
---
{"id": 2, "email": "li@example.org", "plan": {"name": "solo", "seats": 1},
 "invoices": [], "coupon": "WELCOME"}

TypeScript with Customer as the root name, followed by the Go Invoice struct

export interface Customer {
  id: number;
  email: string;
  plan: Plan;
  invoices: Invoice[];
  coupon?: string;
}

export interface Plan {
  name: string;
  seats: number;
}

export interface Invoice {
  number: string;
  total: number;
  paid_at: string | null;
}

// Go
type Invoice struct {
	Number string  `json:"number"`
	Total  float64 `json:"total"`
	PaidAt *string `json:"paid_at"`
}

(The first customer has no coupon, hence coupon?: and ,omitempty.
One invoice total was written 49.0, so Go and Rust get a float.
The unpaid invoice has paid_at: null, which makes it string | null
here, *string in Go, Option<String> in Rust and str | None in Python.)

Tips for best results

  • Pick the Python style by where the data goes: Pydantic when you parse untrusted input, dataclasses for plain containers inside your own code, TypedDict when the data must stay a dict for an existing library.
  • For a paginated API, paste the first and the last page as separate samples. Last pages often lack a next link or carry an empty array.
  • Name the root after the resource. When the top level is an array, a plural root name such as Orders produces Order for the elements.
  • If one stray record turns a field into a union, such as "n/a" among numbers, drop or fix that record before generating; the note names the path.
  • Leave date detection off when any date field mixes formats. A single 03/02/2026 keeps that field a string, which is the safe result.

Edge cases to watch

A key present in every sample is declared required, even when the API documentation calls it optional.

Common errors and how to fix them

Pydantic warns that a field shadows an attribute in BaseModel, or a field reads None
That happens when a hand-written model keeps a key such as json, dict or schema as a field name. The generated model renames those fields (json becomes json_ with Field(alias="json")), so keep the alias when you edit the class.
ImportError: cannot import name 'NotRequired' from 'typing'
NotRequired arrived in Python 3.11. On 3.10, install typing_extensions and change the import to from typing_extensions import NotRequired, TypedDict, or pick the Pydantic or dataclass style.
A Go field tagged json:"-" stays empty after json.Unmarshal
The key contains a double quote, a backslash or a comma, which encoding/json cannot name in a tag, so the field is skipped on purpose and a comment says so. Decode it in a custom UnmarshalJSON, or rename the key at the source. A key that is literally "-" gets the tag json:"-,", which does decode.
Rust fails with "invalid type: null, expected a string"
The samples never had null for that field, so it was generated as String rather than Option<String>. Add a sample with the null and regenerate, or wrap the field in Option by hand.

Best practices

  • Generate every language you ship from the same samples in one sitting, so a TypeScript client and a Go service agree on which fields may be missing.
  • Go through the optional fields with the API documentation open; the generator cannot tell "absent from these samples" from "never sent".
  • Parse untrusted input with the Zod schema or Pydantic model at the edge of the program and let the rest of the code rely on the plain types.
  • Regenerate instead of hand-editing when the payload changes shape, and keep hand-written refinements such as enums or ranges in a separate file.

How each language writes optional and nullable

The two properties are tracked separately because languages treat them differently. In TypeScript a key that may be absent is written coupon?: string, or coupon: string | undefined if you choose that switch, which still requires the key to be present in object literals; a key that may be null gets | null, and a key that may be both gets both. Zod chains .nullable() and .optional() the same way.

Pydantic and dataclasses give a possibly absent field a default, coupon: str | None = None, while a field that is always present but sometimes null keeps no default: paid_at: str | None. Python requires dataclass fields with defaults to follow those without, so the dataclass output moves optional fields to the end of the class. TypedDict wraps possibly absent keys in NotRequired.

Go adds ,omitempty to possibly absent fields and, with the pointer switch on, uses *string for nullable ones, so nil can stand for null; possibly absent structs and times become pointers too, because omitempty has no effect on a struct value. Rust uses Option<T> for both cases, as plain serde cannot tell a missing key from a null, and adds skip_serializing_if = "Option::is_none" to the possibly absent ones so a None is left out when the struct is written back.

How types get their names

The root takes the name typed into the box, Root unless changed, converted to PascalCase, so users becomes Users. A nested object is named after its key, billing_address becoming BillingAddress, and array elements take the singular form of the array's key: users gives User, categories Category, addresses Address, line_items LineItem, children Child. A key whose last word has no separate singular gets Item added, so data gives DataItem, and a key with no letters or digits falls back to Item.

Shapes with the same keys and the same types are declared once. When their candidate names share trailing words, those words become the name, so matching billing_address and shipping_address objects both use Address; otherwise the first candidate wins. Different shapes that want the same name are numbered, User and User2. A name that clashes with a built-in or an import in one of the five languages, such as Option, String, Date, Record, Any or Field, gets Data appended, which is why an options array produces OptionData.

Keys that cannot be used as they are

first-name, 2fa, class and _id are valid JSON keys and poor identifiers. TypeScript and Zod put such keys in quotes. Go builds an exported field name with Go's capitalised initialisms, user_id becoming UserID and avatarUrl AvatarURL, and keeps the original key in the json tag. Rust converts to snake_case, adds #[serde(rename = "...")] whenever the result differs from the key, and writes keywords as raw identifiers such as r#type.

Pydantic models rename and set Field(alias=...): class becomes class_, _id becomes id since Pydantic treats a leading underscore as private, 2fa becomes field_2fa, and a field that would hide a builtin or a BaseModel attribute, such as str or json, gets a trailing underscore. Dataclasses have no alias mechanism, so a renamed field carries a comment with its JSON key. TypedDict switches to TypedDict("Name", {...}) when any key is not usable as an identifier.

encoding/json cannot carry a key containing a double quote, a backslash or a comma in a struct tag, so such a field is tagged json:"-" with a comment saying it needs custom decoding.

What date detection changes

With Detect ISO dates on, a field counts as a date only if every value is either a real date-time with seconds and an offset, 2026-03-02T09:15:00Z or 2026-03-02T09:15:00+02:00, or a real calendar date, 2026-03-02. Zod then writes z.iso.datetime({ offset: true }) or z.iso.date(), both Zod 4 APIs, Pydantic uses datetime or date, Rust uses chrono::DateTime<chrono::Utc> or chrono::NaiveDate, and Go uses time.Time for date-times only, since encoding/json cannot decode a bare date into time.Time. TypeScript keeps string with a comment, and dataclasses and TypedDict keep str, because nothing in those outputs converts the text.

What the generator will not write

No enums or string literal unions: a status field that only ever held three values stays a string, because three samples cannot prove there is no fourth. No tuple types: a positional pair such as a coordinate becomes an array of one element type. No recursive types: threaded data such as comments with replies is expanded only as deep as the samples go.

Unions survive only in TypeScript, Zod and Python. Go and Rust have no anonymous unions, so such a field becomes any or serde_json::Value with a comment naming the kinds seen. Objects used as lookup tables, keyed by IDs or dates, come out as a type with one property per key observed instead of a map, and Zod gets z.number() rather than z.number().int() for whole numbers.

Keeping production payloads on your machine

Types are only trustworthy when they come from real responses, and real responses carry customers' names, emails and street addresses, order histories and now and then an access token buried in a nested object. Sending them to a server-side generator discloses all of that, and which API it came from.

On this page the reading, counting and code generation all run in your tab. The samples are not uploaded and nothing is written to the browser's storage, so a payload copied from production can be used without scrubbing it first.

Frequently asked questions

What if the top level of my JSON is an array?

The root becomes an alias for an array, such as type Root = RootItem[] or pub type Root = Vec<RootItem>, and the records are merged into the element type. Name the root Orders and the elements become Order.

Why are some Go fields pointers and others not?

With the pointer switch on, a field that was null in at least one sample becomes *T so that nil can stand for null, and a struct or time.Time missing from some samples becomes a pointer too, since omitempty never leaves out a struct value. Slices, maps and any can already be nil, so they stay as they are. Turn the switch off for plain values throughout.

Which Python version does the output assume?

Python 3.10 or later, for the X | None syntax. TypedDict output that uses NotRequired needs 3.11, or NotRequired imported from typing_extensions on 3.10.

Do Pydantic aliases change how I read and write the data?

Reading is unchanged: Model.model_validate(data) matches the original keys through the aliases. To write the original keys back, call model_dump(by_alias=True).