Skip to content
Marvin's Toolbox.

JSON Type Generator

Paste JSON and get matching types or schemas for the language you work in, from TypeScript and Zod to Go and Rust. Nested objects become their own named types, optional fields are detected from your data, and each language comes with its own options.

Runs entirely in your browser. Nothing you put in here gets uploaded.

Language
Drop a .json file here or click to browse. You can also paste below.
3 types

TypeScript options

Declarations

Next steps

Keep going. These tools open with your result loaded in.

Format code in JavaScript, TypeScript, JSON, JSON5, HTML, Vue, CSS, SCSS, LESS, Markdown, YAML, GraphQL, XML and SQL. Pick tabs or spaces, set the indent width, and format the input in place with one click.

Convert text into every case at once: title case in the APA, AP, Chicago, MLA, Bluebook, AMA and NYT styles, sentence case, upper, lower, camelCase, snake_case, kebab-case and more.

Count words, characters, sentences, paragraphs, lines and more as you type, with estimated reading and speaking time.

Remove duplicate lines from a list or text, keeping the first occurrence. Optionally ignore case and whitespace, or drop blank lines too.

Replace text in two modes: plain find and replace all, or regular expressions with flag controls and capture group references like $1.

Compare two texts and see every added, removed and changed line highlighted, side by side or inline, with the changed words marked within each line. Ignore case, whitespace or blank lines, read a summary of how much changed, and export the result as a unified diff.

Paste a UUID to see what it carries: version, variant, and for time-based versions the exact timestamp, clock sequence and node. Also shows the raw bytes, the 128-bit integer and the URN form.

Decode Base64 to text or encode text to Base64. Paste into the top box, read the result below, and flip the direction with one click. Handles Unicode correctly, reads URL-safe Base64, and shows binary payloads as a hex dump you can download.

Convert numbers between binary, octal, decimal, hexadecimal and any base up to 36. Type into any field and the others update as you go. Handles huge integers without losing precision and accepts 0x, 0b and 0o prefixes.

About the JSON Type Generator Tool

This tool turns a JSON sample into types you can paste straight into your code, in whichever of its languages you work in. TypeScript, Zod, Go and Rust are supported today. Give it an API response or a config file and it writes matching declarations, with optional fields, nullable values and named types for nested objects all worked out from the data.

Every language shares one reading of your data, so a field that is optional in TypeScript is .optional() in Zod, a pointer with omitempty in Go and an Option in Rust. Each field can carry a comment with an example value from your input, and strings that look like UUIDs, emails, URLs or ISO dates are labelled as such.

What you can do

  • Generate TypeScript interfaces or type aliases from JSON
  • Convert JSON to Go structs with json tags, omitempty and exported names like UserID
  • Generate a Zod schema from JSON, with z.infer types and schemas in dependency order
  • Convert JSON to Rust structs with serde derives and rename_all or per-field renames
  • Detect optional fields from arrays of objects with missing keys
  • Turn nested objects into their own named types, with identical shapes sharing one declaration
  • Recognise recursive data such as trees and linked lists and emit one self-referencing type
  • Annotate every field with an example value and detected formats like UUIDs, emails and dates

How to use the JSON Type Generator

  1. 1Paste your JSON into the input, drop a .json file, or forward data from another tool.
  2. 2Pick the target language and set the root type name.
  3. 3Adjust the options for that language, such as struct tags, .strict() or the derive list.
  4. 4Copy the generated code or download it as a file with the right extension.

Types from a sample, not a schema

The generator reads your example data and infers the widest type it justifies. A key missing from some records of an array becomes optional, and whole numbers mixed with decimals widen to a float. A field that mixes kinds of values becomes a union in TypeScript and the catch-all type elsewhere: any in Go, serde_json::Value in Rust and z.unknown() in Zod, or z.union if you turn that on.

A sample only shows what it contains. A price written as 10.0 reads as a whole number, an empty array says nothing about its elements and a field that is null in every record stays untyped, so check those against the real data. In Go and Rust, a whole number too large for 64 bits becomes a float.

Named types with example comments

Nested objects are hoisted into their own declarations named after their key, so a billing_address object becomes a BillingAddress type and an array under projects holds Project items. Structurally identical objects share one declaration instead of repeating it. Nesting that repeats itself, like children inside children, folds into a single type that refers to itself. With example comments on, each field shows a value taken from your data, truncated when long.

Go structs

Field and type names are exported and follow Go conventions for initialisms, so user_id becomes UserID and image_urls becomes ImageURLs, while the json tag keeps the original key. The output is already gofmt-clean. Optional and nullable scalars and structs become pointers, which you can turn off. Whole numbers become int64 and the rest float64. Turn on time.Time to use it wherever every sample is a strict RFC 3339 timestamp, and write nested structs inline if you prefer them anonymous. Keys that a struct tag cannot spell, such as ones with a comma, are flagged with a comment.

Zod schemas

Every shape becomes a z.object named after its type, ordered so each schema is defined before anything uses it, with .optional() and .nullable() where the data calls for them. Exported z.infer types, .strict(), .int() and format checks such as .email() are all options. Recursive shapes use z.lazy with an explicit type, because z.infer cannot describe a schema that refers to itself. The output works with Zod 3 and Zod 4.

Rust structs for serde

Fields are snake_case and map back to their JSON keys through #[serde(rename_all)] where one convention fits, or a #[serde(rename)] per field if you prefer that. Reserved words become raw identifiers like r#type. The derive list is yours to edit. A trait that a struct cannot derive, such as Eq on a struct that holds an f64, is left off that struct with a note below the code. Direct self references get a Box, so recursive types compile.

Standard JSON only

The input must be valid JSON, the same as your code would parse. Comments, trailing commas and single quotes are not accepted, and an invalid document shows the error with its line and column. To explore the data itself first, use the JSON Inspector. To restyle the generated TypeScript or Zod code, send it to the Code Formatter.

Tools that share a tag with this one.

Convert config and data between JSON, YAML, TOML, JSON5, INI, XML, CSV and .env. Type or paste on the left, pick the output format on the right, and copy the result. Includes a format button and a minify toggle.

Decode Protocol Buffers, MessagePack and CBOR data without a schema. Paste hex or Base64, or drop a file, and see every field as a tree mapped back to its bytes, then copy the result as JSON.

Encode and decode Base16, Base32, Base36, Base45, Base58, Base62, Base64 and Base85. Pick the alphabet variant you need, from Crockford Base32 to Bitcoin Base58 and Ascii85, and convert in either direction.

Decode Base64 to text or encode text to Base64. Paste into the top box, read the result below, and flip the direction with one click. Handles Unicode correctly, reads URL-safe Base64, and shows binary payloads as a hex dump you can download.

Format code in JavaScript, TypeScript, JSON, JSON5, HTML, Vue, CSS, SCSS, LESS, Markdown, YAML, GraphQL, XML and SQL. Pick tabs or spaces, set the indent width, and format the input in place with one click.

Convert a color between HEX, RGB, HSL, HSV, HWB, CMYK, OKLCH and OKLAB. Type into any field and the others update as you go, or pick the color visually. Reads CSS color syntax and keeps alpha where the format supports it.