APIs and data

JSON to types

Paste JSON and get TypeScript types, Go structs and Python models.

Runs in your browserNothing you paste is sent anywhere

An object or an array. Up to 1 MB.

0 B of 1 MB

Paste some JSON to start.

Or press Try an example and I'll fill it in for you.

What it does

It reads a sample of JSON and writes the types for it in three languages: TypeScript interfaces, Go structs with json tags, and Pydantic v2 models for Python. It looks at every item of every array, not just the first one, so a key that only some items have comes out optional, and a field that was ever null comes out nullable. A list that mixes kinds, like numbers and strings, becomes a union. Nested objects get types of their own, named after their keys, and a note under the code tells you why each field is optional or nullable, so nothing is a surprise.

How to use it

  1. Paste an object or an array into the JSON box, or press Try an example.
  2. Change the name of the top type if Root is not what you call it.
  3. Pick TypeScript, Go or Python, then press Copy.

Paste a real response with a few items in it: the more items it sees, the better it guesses which fields are optional.

How I built it

It is plain TypeScript with no library. Your JSON goes through the browser's own parser and nothing else, so nothing is ever run. Before that, one quick pass over the text counts how deep the brackets go, and anything deeper than 64 levels or bigger than 1 MB gets a polite no instead of a frozen tab. Then I merge everything seen at each place in the data into one shape, count how many items had each key and how many sent null, and hand that shape to three small writers, one per language. Keys that a language cannot use as names are quoted in TypeScript, kept in the tag in Go and aliased with Field(alias=...) in Python. A test scans this tool's code for anything that could send data away, which is how "Nothing you paste is sent anywhere" stays true.