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
- 1Paste a sample JSON response.
- 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
- JSON Schema Generator
Generate a JSON Schema (draft 2020-12) from sample JSON — types, nested objects, arrays, required fields and formats like email, date-time and URI.
- HTTP Status Codes
Look up every HTTP status code — 200, 301, 404, 429, 502 and more — with what it means and when servers send it.
- cURL to Code Converter
Convert cURL commands into JavaScript fetch, Python requests or Go net/http code — headers, JSON bodies, auth and methods included.
- Mock API Endpoint Generator
Create a mock REST endpoint in seconds — pick the status code, JSON/XML/text body, custom headers and delay — and call it from your app with CORS enabled.
- AI API Cost Calculator (LLM Token Pricing)
Estimate what an LLM-powered feature will cost — tokens per request, requests per month, input/output prices per million tokens, prompt caching and batch discounts. Works for any model: enter your provider's current prices.
- JSON Formatter & Validator
Format, beautify, validate and minify JSON — with clear line and column error messages and optional key sorting.