Guide

Paste JSON and get TypeScript, Zod, Pydantic, a Go struct, or a Rust serde struct. Arrays are merged so missing keys become optional.

Language
Properties
Modifiers
JSON input
TypeScript output
export interface Root {
  id: number;
  name: string;
  email: string;
  isActive: boolean;
  score: number;
  manager: null;
  address: Address;
  roles: string[];
  orders: Order[];
}

export interface Order {
  orderId: string;
  total: number;
  items: Item[];
  coupon?: string;
}

export interface Item {
  sku: string;
  qty: number;
}

export interface Address {
  street: string;
  city: string;
  zip: string;
}

Guide: JSON to TypeScript, Zod & Go

↑ Back to tool

What is this tool?

This JSON to TypeScript converter reads a JSON document and generates matching type definitions: a TypeScript interface (or type alias), a Zod schema with an inferred type, or a Go struct with json tags. Paste an API response, a config file, or a log line, pick a language chip, and copy the result straight into your codebase. Everything runs in your browser—your JSON is never uploaded.

Unlike a naive one-to-one mapper, the generator merges every element of an array: keys that appear in only some objects become optional, mixed value types become unions, and repeated shapes are de-duplicated into one named type. That makes the output a far better starting point for typing real-world payloads than looking at a single sample object.

💡 Quick tip

Paste an array with several representative items rather than one object. The tool compares all of them, so fields that are sometimes missing are marked optional automatically.

Why use a JSON to types generator?

Hand-writing types for a 40-field API response is slow and error-prone. A JSON to interface generator removes the typing, the typos, and the guesswork about nested shapes, so you can spend time on the logic that uses the data instead.

  • Type a third-party REST or GraphQL response in seconds, then refine the types by hand.
  • Generate a Zod schema from JSON to validate untrusted input at runtime and derive the static type from the same source of truth.
  • Bootstrap Go structs from JSON with correct field casing, initialisms (ID, URL), and tags.
  • Keep client and server contracts aligned across TypeScript and Go services.

Key features

  • Three targets — TypeScript, Zod, and Go from the same input.
  • Root name — Choose the name of the top-level type; nested types are named from their property keys (orders → Order).
  • Array merging — Optional fields, unions, and integer/float widening inferred across all elements.
  • Optional chips — Keep optionality as observed or mark every property optional.
  • Readonly & export — Emit readonly modifiers (or .readonly() in Zod) and toggle the export keyword.
  • interface vs type — Pick your preferred TypeScript style.
  • z.infer — Optionally append type X = z.infer<typeof XSchema>.
  • Shape de-duplication — Identical nested objects reuse one named type.
  • History, Share & session memory — Copy to save an entry, share input plus options, and keep your work when you refresh the tab.

How to use

  1. Paste JSON — Drop an object or array into the input. Use Format to pretty-print or Sample to see an example.
  2. Pick a language — TypeScript, Zod, or Go. The output updates instantly.
  3. Name the root — For example User or ApiResponse.
  4. Tune options — Choose optionality, readonly, export, and TypeScript style.
  5. Copy — Copy the code into your project. The conversion is also saved to History so you can reload it later.

How type inference works

JSON only has six value kinds, but real data is messy. The generator builds an internal type tree and then renders it per language.

JSON valueTypeScriptZodGo
"text"stringz.string()string
42numberz.number().int()int
3.14numberz.number()float64
truebooleanz.boolean()bool
nullnullz.null()any
[1, 2]number[]z.array(z.number().int())[]int
[]unknown[]z.array(z.unknown())[]any
{ … }named interfacenamed z.objectnamed struct
  • Integers vs floats — Whole numbers are int in Go and .int() in Zod. If the same field is 5 in one element and 5.5 in another, it widens to a float.
  • Optional keys — A key missing from some array elements becomes key?: T, .optional(), or a Go pointer with omitempty.
  • Nullable — A field that is sometimes null becomes T | null in TypeScript, .nullable() in Zod, and *T in Go.
  • Mixed types — A field that is a string in one element and a number in another becomes a union (string | number, z.union([…]), or any in Go).
  • Naming — Property keys are PascalCased; plural keys are singularised for array items; name collisions get a numeric suffix.

Output examples

Given this input:

{
  "id": 7,
  "name": "Ada",
  "tags": ["admin", "beta"],
  "address": { "city": "London", "zip": null },
  "orders": [
    { "sku": "A1", "qty": 2 },
    { "sku": "B2", "qty": 1, "gift": true }
  ]
}

TypeScript

export interface Root {
  id: number;
  name: string;
  tags: string[];
  address: Address;
  orders: Order[];
}

export interface Order {
  sku: string;
  qty: number;
  gift?: boolean;
}

export interface Address {
  city: string;
  zip: null;
}

Zod

import { z } from "zod";

export const AddressSchema = z.object({
  city: z.string(),
  zip: z.null(),
});
export type Address = z.infer<typeof AddressSchema>;

export const OrderSchema = z.object({
  sku: z.string(),
  qty: z.number().int(),
  gift: z.boolean().optional(),
});
export type Order = z.infer<typeof OrderSchema>;

export const RootSchema = z.object({
  id: z.number().int(),
  name: z.string(),
  tags: z.array(z.string()),
  address: AddressSchema,
  orders: z.array(OrderSchema),
});
export type Root = z.infer<typeof RootSchema>;

Go

package model

type Root struct {
	ID      int      `json:"id"`
	Name    string   `json:"name"`
	Tags    []string `json:"tags"`
	Address Address  `json:"address"`
	Orders  []Order  `json:"orders"`
}

type Order struct {
	Sku  string `json:"sku"`
	Qty  int    `json:"qty"`
	Gift *bool  `json:"gift,omitempty"`
}

type Address struct {
	City string `json:"city"`
	Zip  any    `json:"zip"`
}

Options explained

  • As observed vs All optional — “As observed” only marks keys optional when the sample proves they can be missing. “All optional” marks every property optional, useful for PATCH bodies, partial updates, or when your sample is tiny.
  • Readonly — Adds readonly to TypeScript properties and arrays, and .readonly() to Zod objects and arrays. Not applicable to Go.
  • Export — Prefixes declarations with export for TypeScript and Zod. Turn it off to paste types inside an existing module.
  • interface / type — Interfaces support declaration merging and extend cleanly; type aliases compose well with unions and mapped types.
  • z.infer type — Adds the inferred static type under each schema so you only maintain the Zod definition.

Use cases

ScenarioHow this tool helps
Typing a REST APIPaste a response from curl or your browser network tab and get ready-to-use TypeScript interfaces.
Runtime validationGenerate a Zod schema for form payloads, webhooks, and environment-driven config.
Go services & SDKsCreate Go structs with json tags for encoding/json decoding.
Mocking & fixturesDerive types from fixture files so tests and mocks stay in sync with the real shape.
DocumentationShow consumers a precise contract alongside example payloads.

Best practices

  • Use several samples — Wrap multiple payloads in an array so optional and nullable fields are detected.
  • Review before committing — Generated types describe the sample, not your business rules. Tighten strings into enums, brand IDs, or use Date where appropriate.
  • Prefer a schema for untrusted data — TypeScript types vanish at runtime; use Zod where data crosses a trust boundary.
  • Rename generically named types — Names derive from keys; rename Data or Item2 to something meaningful.
  • Validate JSON first — Use the JSON Formatter to spot syntax errors, or the JSON Schema tool to validate against a contract.

Common mistakes

  • Trailing commas or comments — JSON does not allow them; the tool shows the parser error so you can fix the input.
  • Single-object samples — A field that is null in your sample becomes null only; provide a second sample with a real value to get T | null.
  • Empty arrays — [] carries no element information and becomes unknown[]. Include at least one element.
  • Dynamic keys — Objects used as dictionaries (IDs as keys) produce one property per key. Replace them with Record<string, T>, z.record(), or map[string]T.
  • Large integers — IDs above 253 lose precision in JavaScript. Treat them as strings.

Limitations

Type generation is inference from examples, so it cannot know about enums, string formats (dates, emails, UUIDs), numeric ranges, or fields that never appear in your sample. Go output uses int and float64 and any for ambiguous values; adjust to int64, time.Time, or custom types as needed. For a formal contract, pair the generated types with a JSON Schema.

FAQ

Is this JSON to TypeScript converter free?

Yes. It runs entirely in your browser with no sign-up and no upload. Copy the generated code as often as you like.

Does it support nested objects and arrays?

Yes. Nested objects become their own named interfaces, structs, or schemas. Arrays are merged across all elements so optional and union types are detected.

Interface or type alias in TypeScript?

Both are supported. Interfaces are the conventional choice for object shapes and allow declaration merging; type aliases are handy when you compose unions or use mapped types. Switch with the chips.

How do I validate data at runtime?

Choose Zod. Parse incoming data with RootSchema.parse(data) or safeParse, and use the inferred type for static checking.

Why are some Go fields pointers?

Optional or nullable fields become pointers (for example *string) with omitempty, so encoding/json can tell the difference between a missing value and a zero value.

Can I generate types for a JSON array at the top level?

Yes. A root array becomes an alias such as type Root = RootItem[] (or the Zod/Go equivalent), with an item type named from your root name.

What happens with invalid JSON?

The tool shows the parser message instead of output. Fix the syntax (quotes, commas, brackets) and the types update live.

Can I share my conversion?

Yes. Use Share to create a link containing your JSON and options. Copying output also adds a reloadable entry to History on this device.

Core: json to typescript, json to interface, json to zod, json to go struct, json to types online, typescript interface generator, generate types from json.

Tooling: quicktype alternative, json2ts, transform.tools json to typescript, zod schema generator, z.infer, json-to-go, go json tags.

Concepts: type inference from json, optional properties, nullable fields, union types, runtime validation, api response types, encoding/json struct.

Similar tools

You might also find these developer tools useful:

Conclusion

This JSON to TypeScript, Zod and Go converter turns real payloads into typed code in one paste, with smart merging of arrays, readable names, and options for optional, readonly, and export styles. To clean up input first, use the JSON Formatter; to extract values from large payloads, try the JSONPath Tester.