Developer 🔒 Runs in your browser — no data sent to servers

JSON to Types

Turn a JSON sample into TypeScript interfaces, Go structs, Python models, C# classes, Rust structs or a JSON Schema.

JSON to Types - TypeScript, Go, Python, C#, Rust and JSON Schema

Paste a JSON sample, such as a response from an API, and get the type definitions to go with it: TypeScript interfaces, Go structs with JSON tags, Pydantic models or dataclasses, C# classes, Rust structs for serde, or a JSON Schema. Nested objects become their own named types, so the result reads like code a person would write.

API responses often contain real customer data, tokens and internal IDs. The conversion runs entirely in your browser, so none of it is sent anywhere.

How to use it

  1. Paste JSON into the left box, or press Sample to see an example.
  2. Choose the Output language.
  3. Set the Root name of the top-level type; for TypeScript, choose interface or type.
  4. Copy the result into your project.

How the types are worked out

  • Numbers become integers when every value is whole, and floating-point otherwise: 42 and 18.5 in the same field give a float.
  • Arrays of objects are merged: every key seen in any item appears in the type.
  • Optional fields: with Mark missing keys optional on, a key missing from some items becomes optional (coupon?: string, omitempty, Option, = None).
  • Nullable fields: a value that is null in one item makes the field nullable, for example string | null or *string in Go.
  • Mixed types, such as a number in one item and a string in another, give unknown, Any or interface{}, so you can decide by hand.
  • Names come from the keys: address gives Address, and the items of orders give Order. Objects with the same shape share one type.

Per language

OutputWhat you get
TypeScriptexport interface or export type; keys that are not valid names are quoted
GoExported structs with json tags, int64 and float64, and common initialisms such as ID and URL
Python (Pydantic)BaseModel classes; snake_case fields with Field(alias=...) when the JSON key differs
Python (dataclass)@dataclass classes, with optional fields placed last as dataclasses require
C#Classes with [JsonPropertyName] for System.Text.Json, long, double and List<T>
RustStructs deriving Serialize and Deserialize, with #[serde(rename)] where needed
JSON SchemaA draft 2020-12 schema with required lists, ready for validators

Get the most accurate types

A type is only as complete as the sample it came from. Use a response that includes every optional field at least once, and paste an array with several different items rather than one, so the merging can see which fields vary. Dates arrive in JSON as strings and stay strings; convert them in your code where you need real date types.

Related tools

To tidy or validate the JSON first, use the JSON formatter. To turn it into YAML, CSV or XML, use the JSON converter. The task pages open this tool with a language chosen: JSON to TypeScript, JSON to Go, JSON to Python, JSON to C# and JSON Schema generator.

Guides