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.
16 lines · processed in your browser, nothing is uploaded
TypeScript output · root.ts
Generated code appears here.How to generate types from JSON
- 1Paste a JSON object or array into the input panel.
- 2Choose the target language, such as TypeScript or Go.
- 3Give the top-level type a meaningful name, such as User or Order.
- 4Adjust the language options if you need a different output style.
- 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.