JSON to TypeScript, Go and Python: Generate Types From a Sample

What is it?

JSON to TypeScript, Go and Python generates typed code from a JSON sample: TypeScript interfaces, Go structs or Python dataclasses.

Who is it for?

TypeScript, Go and Python developers who need typed models for API data quickly.

How to use it

  1. Paste a JSON sample, such as an API response.
  2. Choose the Language and the Main type name (like User or Order).
  3. Copy the generated code.

Get better types

  • Paste a sample with every field present. Fields missing from your sample won’t appear in the types.
  • If a field can be null or missing in real data, mark it optional yourself (? in TypeScript, a pointer or omitempty in Go, Optional[...] in Python).
  • Arrays are typed from their items; mixed arrays become a union or any.
  • Dates arrive as strings in JSON; convert them in your code.

Good to know

Large numbers like IDs above 2⁵³ lose precision in JavaScript; keep such IDs as strings. Generated names follow each language’s style (Go fields are capitalised with json tags).

If you see This is not valid JSON, check it with the JSON Formatter first.

Worked example

From {"id": 7, "name": "Asha", "tags": ["vip"], "address": {"city": "Pune"}} with type name User, TypeScript gets an interface User with id: number, name: string, tags: string[] and a nested Address interface with city: string.

Tips for real APIs

  • Merge several samples first, so fields that appear only sometimes are included.
  • Check number fields: an ID like 0012 sent as a string should stay a string.
  • For Go, add omitempty to optional fields; for Python, give optional fields a default of None.

Related tools

JSON Formatter & Validator · JSON Compare

Errors and how to fix them

  • This is not valid JSON: fix the sample first (trailing commas, single quotes).
  • Fields typed as any or unknown: the sample had null or an empty array there; use a fuller sample.

Open the tool: JSON to TypeScript, Go and Python

Still stuck?

Contact support. Tell us which tool or page you were using, what you tapped, what you saw, and your phone or computer and browser (for example: Android phone, Chrome). We reply by email.

Questions, or an error not listed here?

Tell us in the comments: what you were doing, the exact message you saw, and your device and browser. We read every comment and add new fixes to this article.