N
NJHTools

JSON to Types: Generate Code from JSON

Paste a JSON sample and instantly get matching types for TypeScript, Zod, Go, Python, Java, C#, Kotlin, Swift, Rust, Dart or JSON Schema. It is free, needs no signup, and runs entirely in your browser with quicktype, so nothing is uploaded.

Language

16 lines · processed in your browser, nothing is uploaded

TypeScript output · root.ts

Generated code appears here.

How to generate types from JSON

  1. 1Paste a JSON object or array into the input panel.
  2. 2Choose the target language, such as TypeScript or Go.
  3. 3Give the top-level type a meaningful name, such as User or Order.
  4. 4Adjust the language options if you need a different output style.
  5. 5Copy the generated code into your project.

How type inference from JSON works

The generator reads every value in your sample and infers a type for it: strings, numbers, booleans, nested objects and arrays. Nested objects become their own named types, and objects with the same shape are merged so you do not get duplicates.

Inference can only see what is in the sample. If a field is null in every record, the generator cannot know its real type, so replace null with a realistic value or edit the result by hand.

Getting accurate optional and union types

Paste an array of several records rather than a single object. Fields missing from some records are marked optional, and fields that hold different types across records become unions or the closest common type the target language supports.

Real API responses vary between endpoints and error cases. Combine a success response and an edge-case response into one array to get types that survive production data.

Why generate types instead of writing them

Hand-written types drift from the real payload and typos in field names compile happily. Generating from a real response gives you a correct starting point in seconds, which you can then rename and refine.

Treat the output as a draft: rename generic types, tighten string fields that are really enums, and add documentation comments before committing.

Frequently Asked Questions

Is my JSON uploaded to a server?↓

No. The code generator (quicktype) runs entirely in your browser, so the JSON you paste never leaves your device. That makes it safe to use with internal API responses, though you should still strip secrets before sharing generated code.

How are optional fields detected?↓

Types are inferred from the sample you paste. A field becomes optional only if it is missing from some of the objects, so paste an array with several representative records, or mark the field optional by hand after generating.

Which languages are supported?↓

TypeScript, Zod, Go, Python, Java, C#, Kotlin, Swift, Rust, Dart and JSON Schema. Each language has its own page with tips on the idioms of that ecosystem.

Does it handle nested objects and arrays?↓

Yes. Nested objects become separate named types, arrays become typed lists, and arrays of arrays are supported. Objects that share the same shape are merged into one type.

What powers the code generation?↓

quicktype, an open-source (Apache-2.0) type generator, compiled to run in the browser. The page adds no server step, so the output is the same whether you are online or on a slow connection once it has loaded.

Last updated: