Skip to content
Accessibility
Theme
Text size
High contrast
Limit animations
Readable fontAtkinson Hyperlegible
Increased text spacing
Underline links
Always show focus

Runs in your browser — nothing you paste is uploaded.

JSON → Types

Paste a JSON sample and get TypeScript interfaces or Go structs. Handles nested objects and arrays. Runs in your browser.


    

What it does

Paste a JSON sample and get ready-to-use TypeScript interfaces or Go structs. It reads the structure of your data and writes one type per object: keys become fields, nested objects become their own named types, and arrays take the type of their first element. The output regenerates as you type and switching language reshapes it instantly.

How the mapping works

  • Strings → string.
  • Booleans → boolean (TS) / bool (Go).
  • Numbers → number (TS); in Go, a whole number becomes int and one with a decimal part becomes float64.
  • Nested objects → a named type, e.g. a meta object yields a Meta interface/struct referenced from the parent.
  • Arrays → the element type with [] (TS) or [] prefix (Go); an empty array or null falls back to any / interface{}.

Field names are kept as-is for TypeScript (quoted if they aren't valid identifiers), while Go gets exported PascalCase names with a json:"..." tag preserving the original key.

Worked example

The input {"id":1,"name":"Ada","tags":["a","b"],"meta":{"active":true}} produces a Meta type with an active boolean and a Root type whose fields are id (number/int), name (string), tags (string array) and meta (the Meta type). In Go each field carries its matching json tag so it round-trips through encoding/json.

Limitations and gotchas

Inference comes from a single sample, so results are a strong starting point rather than a finished schema. The top-level value must be an object, not an array. Optional and sometimes-missing keys all come out required; null values become any/interface{} because the real type is unknowable from null; and mixed arrays are typed from the first element only. Review numbers in Go especially — a field that is 0 in the sample is typed int even if it can hold decimals.

When to use it

Ideal for scaffolding types from an API response or a config file so your editor gets autocompletion and your build catches shape mismatches. Tidy or validate the JSON first with the JSON formatter, or convert from other formats with YAML ↔ JSON and CSV ↔ JSON.

Privacy

Generation is local; nothing is uploaded.

Frequently asked questions

Why does my top-level JSON array give an error?

The generator needs a named shape to start from, so the top-level value must be a JSON object ({ ... }), not an array or a bare value. If your sample is an array, generate the type for a single element and then declare the array yourself as ElementType[] in TypeScript or []ElementType in Go.

How are optional and nullable fields handled?

Inference comes from one sample, so every key present becomes required and a null value becomes any (TS) or interface{} (Go), because the type can't be known from null alone. Fields that are sometimes missing won't be marked optional. Add ?, pointers, or union types where your data actually varies.

Why are all numbers typed as int or number?

JSON has a single number type, so the tool infers from the sample value. In Go an integer-valued number becomes int and one with a fractional part becomes float64; in TypeScript every number is just number. A field holding a whole number like 0 is typed int even if it can hold decimals elsewhere, so widen it to float64 where needed.

Related tools