JSON to TypeScript & Go Struct Converter
Generate TypeScript interfaces or Go structs from a JSON sample. Inference reflects that sample, not every valid record; review nullability, optional fields, numeric precision, names, and the generated declarations before use.
Turn JSON Into Type-Safe Code
When you consume an API or load a config file, the data arrives as untyped JSON. Hand-writing the matching TypeScript interfaces or Go structs is tedious and error-prone. This tool infers a complete type definition from a single representative JSON sample, so you can paste the response from your API and drop the generated types straight into your codebase.
How the Type Inference Works
- Objects become named interfaces (TypeScript) or structs (Go), with a separate named type for each nested object.
- Arrays are typed from their elements —
string[]in TypeScript,[]stringin Go. Arrays of objects produce a reusable item type. - Numbers map to
number(TS) orint/float64(Go, based on whether the value is whole). - Go struct tags — every field gets a
`json:"originalKey"`tag so marshalling round-trips the exact JSON keys, even when the Go field name is PascalCased. - Mixed arrays in TypeScript produce a union type (e.g.
(number | string)[]). Go uses only the first element and requires manual review for heterogeneous arrays.
Tips for Best Results
Give the tool a complete example — include every optional field at least once so it appears in the generated type. TypeScript examines all array elements and combines their types. Go uses the first element, so provide a representative homogeneous array and review mixed arrays manually. You can rename the top-level type with the "Root type name" box; nested types are named automatically from their keys.
Privacy
Input processing is local to this tool. Shared page features may make network requests, and enabled browser drafts may retain text locally. Avoid pasting credentials or confidential material.
Frequently Asked Questions
export interface for the root object plus one for every nested object, with arrays and primitives typed automatically.`json:"key"` tag matching the original JSON key, so encoding/json marshals and unmarshals correctly.items: Item[] / Items []Item).null value becomes null (TS) or interface{} (Go). To capture optional fields, include them in your sample JSON with a representative value.