Utilo

JSON to Types

Generate Go structs, Rust serde structs, Zod schemas, Pydantic models, Kotlin data classes, Java records, C# classes, Swift Codable and TypeScript types from JSON. Detects optional and nullable fields across arrays.

What this JSON to types generator does

Writing model classes by hand for a big API response is slow and error-prone. Paste a JSON sample and this tool infers a complete type model and prints it as Go structs with json tags, Rust structs with serde derives, Zod schemas, Pydantic models, Kotlin data classes, Java records, C# classes, Swift Codable structs or TypeScript interfaces. Nested objects become their own named types, arrays of objects are merged so that every field seen in any element is captured, and the inference runs in a Web Worker so even multi-megabyte samples don't freeze the page.

How to use it

  1. Paste JSON into the input or load the sample.
  2. Set the root type name, for example User or OrderResponse.
  3. Pick the target language tab. Output regenerates instantly.
  4. Copy the code into your project and adjust names or types where your domain knowledge beats inference.

How inference works

  • Optional fields: if a key is missing in some elements of an array, it is marked optional (? in TS, Option<T> in Rust, omitempty in Go, = None in Pydantic).
  • Nullable fields: a null value makes the field nullable in the target language.
  • Numbers: integers and floats are tracked separately, so 42 becomes int64/i64/Long while 4.2 becomes a float type.
  • Mixed types: when the same field holds different types, languages with unions (TypeScript, Zod, Pydantic) get a union, and the others fall back to a generic JSON value type.
  • Naming: keys like user_id or created-at are converted to idiomatic field names per language, with the original key preserved in tags or annotations (json:"user_id", #[serde(rename)], @SerialName, CodingKeys).

Tips

  • Feed it a representative sample. A single object with an empty array tells the tool nothing about the array's items.
  • Merge several responses into one top-level array to capture optional fields reliably.
  • Zod output exports both the schema and the inferred type, so you get runtime validation and static typing together.

Frequently asked questions

Is my JSON uploaded anywhere?

No. Parsing and code generation happen in your browser in a background worker.

Why is a field typed as any or interface{}?

It was null in every sample, or an empty array, so no concrete type could be inferred. Provide a sample with a real value.

Does it handle dates?

JSON has no date type, so ISO strings stay strings. Change them to time.Time, datetime or Date by hand if your decoder supports it.

Can I generate JSON Schema?

Use the Zod or Pydantic output; both libraries can export JSON Schema directly.

Yes. All processing happens directly in your browser using JavaScript, Web Workers and Web APIs. Nothing you type, paste or upload is sent to our servers.