Skip to content

Generate TypeScript interfaces, Go structs or Zod schemas from a JSON sample.

Loading tool

About JSON to Types

Generates TypeScript interfaces or type aliases, Go structs with json tags, or Zod schemas from a JSON sample. Nested objects become named types, items in arrays are merged so keys missing from some items become optional and null values become nullable, and identical shapes are reused. Options include the root type name, export keywords, Go omitempty and pointer handling, and z.infer type exports for Zod.

Common uses

  • Type an API response in a TypeScript frontend
  • Create Go structs for decoding a JSON payload
  • Generate a Zod schema to validate incoming JSON at runtime
  • Get a starting point for types from a webhook or config sample

FAQ

How accurate are types inferred from a JSON sample?
They only reflect the sample. A field that is always a string in the sample may be a number or null in other responses, so review the result and use several representative samples where possible.
Interface or type alias in TypeScript?
For plain object shapes both work. Interfaces can be extended and merged by declaration, while type aliases can also express unions and other non-object types.
What does omitempty do in Go json tags?
With omitempty, encoding/json leaves a field out of the output when it has its zero value, such as 0, an empty string, nil or an empty slice.
Why use Zod instead of only TypeScript types?
TypeScript types are removed at compile time and do not check data at runtime. A Zod schema validates the actual JSON when it arrives and can also produce the TypeScript type with z.infer.