Skip to content

JSON to TypeScript Converter

Turn JSON into TypeScript, Zod, Go, Python, Rust and more. Runs in your browser.

Loading tool…

About this json to typescript converter

This converter reads a JSON sample and writes matching types for TypeScript, Zod, Go, Python, Rust, Java, C#, Kotlin, Swift or Dart. It is for developers who have an API response in front of them and don't want to type out forty fields by hand.

The work is done by quicktype, an open-source type inference engine, running inside this page. It looks at every object in your sample, merges objects that share a shape, marks keys that are sometimes missing as optional and gives nested objects their own named types. The engine downloads once, about 270 KB compressed. After that, the output updates as you edit the JSON.

Nothing you paste is uploaded. That matters when the sample is a real customer record or a response with tokens in it. If the JSON has a syntax error, you get the line and column first. You can also tidy it up in the JSON formatter before you start.

Features

  • Ten target languages

    TypeScript interfaces or type aliases, Zod schemas, Go structs with json tags, Python dataclasses or Pydantic models, Rust structs with Serde, Java, C#, Kotlin, Swift and Dart.

  • Optional fields from real data

    Every item in an array is compared. A key present in one object and missing in another becomes optional, so the type matches the data you actually get, not just the first item.

  • Named nested types

    A nested customer object becomes its own Customer type, and items in an items array become Item. Change the top-level name and the file name follows.

  • Dates, enums and maps

    ISO 8601 strings can become Date or time.Time, and UUIDs can be recognized. Repeated short strings can become enums. Objects whose keys are IDs can become maps instead of huge classes.

  • Per-language switches

    type instead of interface and readonly for TypeScript, omitempty for Go, Pydantic for Python, PartialEq for Rust, Lombok for Java, kotlinx.serialization for Kotlin, class instead of struct for Swift and freezed for Dart.

  • Types only, or with helpers

    By default you get clean type declarations. Turn off Types only to also get the parse and serialize helpers quicktype writes for many languages.

How to use the json to typescript converter

  1. 1Pick a language, such as TypeScript, Zod or Go.
  2. 2Paste a JSON sample. The engine loads once, then types update as you edit.
  3. 3Adjust names and options, then copy or download the file.

When to use it

  • Typing a third-party API response

    Call the endpoint, copy the JSON from the Network tab, paste it here and drop the interfaces into your api.ts. Ten minutes of typing becomes ten seconds.

  • Validating input at runtime with Zod

    TypeScript types vanish when the code compiles, so they cannot check data from the network. A Zod schema can. Generate it, then call Schema.parse(data) where the data enters your app.

  • Writing a Go client

    Get structs with json:"field_name" tags and Go-style field names. Optional fields become pointers, and omitempty keeps them out of the JSON you send back.

  • Modelling a webhook payload

    Collect three or four real payloads into one array and paste it. Fields that only some events carry turn optional, which is exactly what your handler needs to know.

  • Starting a test fixture

    Make realistic records with the fake data generator, then generate the types that go with them.

How does JSON to TypeScript conversion work?

The generator walks the JSON and records a type for every value: string, number, boolean, null, array or object. Objects in the same array are merged into one shape. If a key appears in every object it is required. If it appears in only some, it becomes optional with a question mark in TypeScript, a pointer in Go or a field with a None default in Python.

Numbers get a closer look in languages that care. 42 becomes int64 in Go and long in Java, while 12.95 becomes float64 or double. If one item has 3 and another has 3.5, the field is a float.

A value that is null in every sample gives the generator nothing to work with, so it is typed as null or any. Paste a sample where that field has a real value, or edit the type afterwards.

Should I use an interface or a type alias?

For plain object shapes from JSON, both work and compile to nothing. Interfaces can be extended and merged, and many teams use them for API models. Type aliases can also express unions and mapped types. The TypeScript handbook says the two are very similar and that you can often choose between them freely.

Pick whatever your codebase already uses. The type instead of interface switch changes the output in one click.

Why generate a Zod schema instead of a type?

A TypeScript type is erased at compile time. If the server sends a string where you expected a number, nothing stops it. Zod checks the value while the code runs and throws a clear error at the boundary.

The Zod output includes both: a schema such as OrderSchema and a type made with z.infer, so the schema and the type cannot drift apart. You need the zod package in your project; this page only writes the code.

Getting better types from your sample

The output can only be as good as the JSON you give it. A few habits help a lot:

  • Include several items in each array, including one with optional fields missing.
  • Replace null placeholders with a real example value.
  • Paste the raw response, not a pretty-printed excerpt you trimmed by hand. Missing keys you deleted would turn into optional fields.
  • Check numeric IDs. A value like 9007199254740993 is larger than JavaScript can store exactly, so keep such IDs as strings in the API and in the type.

Why use Mavros

 MavrosTypical upload sites
Where your JSON goesStays in your browserOften posted to a server
LanguagesTen, including Zod, Go, Rust, Kotlin and DartTypeScript only
Optional fieldsWorked out from every item in an arrayTaken from the first item only
Error messagesLine and column of the JSON error"Invalid JSON"
Download sizeShown before the engine loadsNot mentioned

Tips

  • Name the top level after the endpoint, such as Order or SearchResult. Nested types are named from their keys, so items becomes Item.
  • Turn on Make every property optional for patch payloads, where any field may be left out.
  • If the source is YAML or CSV, convert it to JSON first, then paste it here.
  • Compare two versions of an API response with JSON diff to see which fields changed before you regenerate the types.
  • Go structs use omitempty on optional fields by default here. Turn it off if your API expects the key with a null value.

Questions

How do I convert JSON to a TypeScript interface?

Paste the JSON, keep TypeScript selected and load the engine. Interfaces appear on the right, one per nested object, ready to copy or download as a .ts file.

How are optional properties detected?

A key that is missing from some objects in the same array becomes optional. With only one object, every key looks required, so paste several real items when you can.

Can it generate a Zod schema from JSON?

Yes. Choose Zod and you get a schema for each object plus an inferred TypeScript type. Add the zod package to your project to use it.

Does it convert JSON to Go structs with json tags?

Yes. Choose Go. Each field gets a json:"key" tag with the original key, optional fields become pointers, and omitempty is added unless you switch it off.

What happens to null values?

A field that is null in some items and a string in others becomes an optional or nullable string. A field that is null everywhere has no real type to infer, so give it a sample value.

Why is the engine a separate download?

quicktype is a full compiler for ten languages, about 270 KB compressed. Loading it only when you ask keeps the page fast. Your browser caches it after the first time.

Are dates turned into Date types?

Strings in ISO 8601 format, like 2026-10-28T14:03:11Z, become Date in TypeScript, time.Time in Go and datetime in Python while Detect dates is on. Turn it off to keep them as strings.

Is my JSON uploaded?

No. The engine runs in your browser tab, and the JSON never leaves your device. You can load the page, go offline and keep generating types.