PUBLIC.INTERNET

JSON to Types Generator

Paste a JSON value and the tool writes matching type definitions on every keystroke. Pick TypeScript for interfaces, Zod Schema for z.object definitions plus inferred types, or Go Struct for structs with json tags. Nested objects become their own named types, and the Root Type Name field sets the top-level name. Types are inferred from the sample you paste, and every item of an array is checked, so read the output as a first draft to review rather than a finished contract.

Generated types

          

How to generate types from JSON

  1. Paste JSON into Input JSON, or click Load Example to see a user record with a nested profile and a list of posts.
  2. Set Root Type Name (it starts as User) to the name of the resource your API returns. Names use ASCII letters and digits only, so accents are dropped and other characters are left out. When the name used differs from what you typed, the note under the field shows it, such as Root when no letter or digit is left or Date2 for a built-in name like Date.
  3. Choose TypeScript, Zod Schema, or Go Struct in the dropdown above the output. The result updates as you type.
  4. If an Invalid JSON message appears, fix the syntax problem it points to, such as a trailing comma or single quotes. The old output is cleared until the JSON parses.
  5. Click Copy and paste the result into your project. Fields missing from some array items come out optional and fields that are sometimes null come out nullable; anything your sample never shows still needs a manual check.

Why one sample is not a schema

Every value of every array item is typed. A number written with a decimal point or an exponent, such as 10.0 or 1e2, becomes float64 in Go even when it is whole, because encoding/json will not decode it into an int, and so does a whole number of size 2^53 or more, such as a 64-bit ID. A field that is null in some items becomes nullable (| null, .nullable(), and in Go a pointer for strings, numbers, booleans and objects). Mixed kinds become a union (interface{} in Go), objects are merged with keys missing from some items marked optional, an empty array becomes any[], z.array(z.any()) or []interface{}, and a top-level array becomes a list type of its items.

Generated names use only ASCII letters and digits, which every compiler accepts. Accents are dropped (café becomes Cafe), other characters split words (first_name becomes FirstName), and a name with no ASCII letters or digits becomes Item, or F for a Go field, numbered when taken. Keys keep their exact text in TypeScript and Zod, quoted when needed, and in the Go json tag. A tag holds only letters, decimal digits, spaces and ASCII punctuation except quotes, apostrophes, commas, backslashes and backticks; any other key, or an empty one, gets a comment instead. Go also ignores a tag holding a letter or digit newer than its Unicode tables (15.0 in Go 1.26). Go will not read those keys.

Use the output to skip the typing when you are wiring up an API response, then tighten it against the API documentation or an OpenAPI file before you rely on it, because fields that never appear in your sample cannot be known. The conversion is JSON.parse plus a second look at how each number was written, followed by string building in the page, so pasting a real response does not send it anywhere. Two inputs stay unreliable: an optional key named like a built-in object member, such as toString, can make the TypeScript and Zod output reject a sample that lacks it, and 1e400 overflows to infinity, which Zod and Go reject.