Account

What new tool do you want?

Developer Tools

JSON to TypeScript / Go Types

Generate TypeScript interfaces or Go structs from sample JSON — nested objects, arrays and optional fields inferred automatically.

How to use

  1. 1Paste a sample JSON response.
  2. 2Pick TypeScript or Go and a root name, then copy the generated types.

Frequently asked questions

How are optional fields detected?

When an array contains several objects, any key missing from some of them is marked optional (?: in TypeScript, omitempty in Go).

What happens with null values?

A value that's always null is typed null (interface{} in Go). If it's sometimes a string, you get string | null or *string.

How accurate are the types?

They match the sample you provide. Include a representative response — edge cases missing from the sample won't be in the types.

Worked example: JSON to TypeScript / Go Types

Paste {"id":1,"name":"A","tags":["x"],"owner":{"email":null},"items":[{"sku":"a","qty":1},{"sku":"b","price":2.5}]} and you get three interfaces, not one: Root with id: number, name: string, tags: string[], owner: Owner and items: Item[]; an Item interface where sku is required but qty and price are both marked optional (sku?: number — written as qty?: number) because neither key appears in both array elements; and an Owner interface where email is typed null, since that's the only value the sample ever showed. The tool names the nested types after the array/field they came from (Item, Owner) rather than generating anonymous inline types, which keeps the output readable for deeply nested API responses.

How optional fields get inferred

There's no schema involved — the tool looks across every object in an array and marks a key optional the moment it's missing from even one element. That's a direct, mechanical rule: {"user_id":1,"nick":"a"} alongside {"user_id":2,"nick":null} produces a Go struct where Nick is a *string (a pointer, Go's way of expressing optional/nullable) because one record had a real string and the other had null. The practical implication is that your sample needs to be representative — if every record in your sample happens to include a field that's sometimes missing in production, the generated type will incorrectly mark it as required.

Why Go and TypeScript need different tricks for the same JSON

TypeScript can express "string or null" directly as a union type, but Go has no built-in nullable primitive — the generator reaches for a pointer (*string) instead, and separately emits a `json:"user_id"` struct tag so Go's encoding/json package maps the snake_case API field to the idiomatic PascalCase Go field name (UserId). Getting this translation right by hand for a large API response is tedious and error-prone; this tool does the field-name conversion and null-handling consistently in one pass, entirely in your browser — no response payload is ever sent anywhere.

A blank root name is replaced with Root

Language opens on a TypeScript interface. The other choices are a TypeScript type and a Go struct. Root name opens on Root, and if I clear the box it is filled back in as Root before anything is generated. Bad JSON stops with a line and a column, and I get no type at all. A single object and a list are both accepted. In the sample, two items that do not share every field become optional on the fields that are missing from one of them, while a field that is present and null stays a null type rather than being dropped. The Go choice writes a slice when the JSON is a list, and it keeps the original key in a tag beside a renamed field.

Related tools

More: Developer Tools