Skip to content
Webmaster Tools
JSON & dataJSON to Types

JSON to TypeScript & Go Types

TypeScript, Go and more from JSON.

Paste a sample payload

      
Valid JSON Invalid JSON Fields missing from some array items are optional; mixed types become unions. Runs in your browser

About JSON to TypeScript & Go Types

Paste a sample API response and this tool writes the types for it: TypeScript interfaces, Go structs with json tags, Python dataclasses and a JSON Schema (draft 2020-12). It saves typing out a large payload by hand and catches fields you would have missed.

Types are inferred from every value in the sample. All items of an array are merged, so a field that is missing from some items becomes optional (coupon?: in TypeScript, omitempty in Go, = None in Python), and a field with different types becomes a union (string | number) or any in Go with a comment. Nested objects become named types, using the key in PascalCase and singular for array items (orders gives Order). Whole numbers become int64 in Go and int in Python, others float64 and float. Go field names follow Go style, with initialisms such as ID and URL.

How to use it

  1. Paste JSON on the left, or click Load sample.
  2. Set the root type name, then pick a language tab.
  3. For TypeScript choose interface or type and whether properties are readonly; for Go choose whether nullable fields become pointers.
  4. Copy the code or download it.

Examples

Common questions

How accurate are the types?

They describe the sample, not the API contract. Paste several representative responses inside one array so optional and nullable fields show up.

Which Python version do the dataclasses need?

Python 3.10 or later, because they use str | None and list[str].

Why is a number typed as float64?

At least one value had a decimal point or exponent, such as 20.0 or 1e3.