JSON to TypeScript, Zod, Go, Rust and Python
Paste an API response or any sample JSON and get ready-to-use types. Every item of every array is looked at, so fields that are sometimes missing or null are typed that way.
How to turn JSON into types
- Paste sample JSON, such as an API response, or drop a
.jsonfile. Types appear on the right as you type. - Pick a language: TypeScript, Zod, Go, Rust or Python. The choice is kept in the link, so
/json-to-types#goopens Go. - Set the Root name for the top-level type. Nested objects are named after their keys, and array items after the singular (
usersgivesUser).
How the types are inferred
- Every array item counts. If a key appears in some items but not others, it becomes optional (
?in TypeScript,.optional()in Zod,omitemptyin Go,Optionin Rust,= Nonein Python). - null makes a field nullable:
string | null,*string,Option<String>,str | None. - Numbers: whole numbers become integers where the language has them (
int64,i64,int,z.number().int()); any decimal makes the field a float. - Identical shapes share a type, so a billing and a shipping address with the same fields both use
Address. - Keys that aren't valid identifiers are quoted in TypeScript and Zod, and get
jsontags,#[serde(rename)]or Pydantic aliases elsewhere.
The more varied your sample, the more accurate the types: include an item with the optional fields filled in and one without.
Questions
Is my JSON uploaded?
No. Types are generated in your browser. Nothing you paste is sent anywhere.
How do I generate a TypeScript interface from JSON?
Paste the JSON and keep TypeScript selected. Switch Declare as to type if you prefer type aliases over interfaces.
How do I convert JSON to a Go struct?
Choose Go. Fields get exported Go names with common initialisms (ID, URL, API) and json tags; optional fields get omitempty and nullable ones become pointers.
Does it generate Zod schemas?
Yes. Choose Zod to get a schema per object plus z.infer types, with .optional() and .nullable() where your data needs them.
Why is a field typed as optional?
Because at least one item in an array didn't have it. Add it to every item in your sample if it is always present.
What happens with an empty array or object?
An empty array has no items to learn from, so its items are unknown (any in Go, serde_json::Value in Rust, Any in Python). An empty object becomes a free-form map.
Which Python and Rust libraries does it target?
Python output is Pydantic v2 models with modern list[...] and X | None syntax. Rust output uses serde with Serialize and Deserialize derives.