JSON to Types
Turn a JSON sample or a JSON Schema into TypeScript, Zod, Go structs, Python dataclasses, Kotlin data classes, or Java records/Lombok. Infers optional and nullable fields. Runs in your browser.
Prefer the terminal? See the CLI equivalent →About the JSON to Types
- TS, Zod, Go, Python, Kotlin & Java
- JSON sample or JSON Schema
- Syntax highlighting
- Instant results
- 100% private — runs in your browser
- Free, no sign-up
Paste a JSON sample — or a JSON Schema — and get ready-to-use type definitions in the language of your choice: TypeScript interfaces, a Zod schema (with an inferred type), Go structs with JSON tags, Python dataclasses, Kotlin data classes, or Java records / Lombok @Data classes. It saves the tedious, error-prone job of hand-writing types to match an API response, config file, or spec.
From a JSON sample it infers structure the way a careful developer would: nested objects become their own named types; arrays of objects are merged into a single type; a field missing from some array elements is marked optional; and a field that is ever null is made nullable. From a JSON Schema it uses the declared information directly — the “required” list drives optionality, a "null" type makes a field nullable, and local “$ref” definitions become shared named types. Integers and floats are distinguished where the target language cares (Go and Python).
Everything runs in your browser — what you paste never leaves your device, which matters when the sample comes from a real API response that may contain private data.
How to use it
- Choose the input mode — a JSON sample or a JSON Schema — then paste or upload it in the left editor.
- Choose a target: TypeScript, Zod, Go, or Python.
- Optionally rename the root type (defaults to “Root”).
- Copy or download the generated definitions from the right editor’s toolbar.
How types are inferred
- Nested objects
- Each becomes its own named type, referenced from the parent.
- Arrays of objects
- Merged into one type covering every key seen across elements.
- Optional fields
- A key absent from some array elements is marked optional (?, omitempty, = None).
- Nullable fields
- A value that is ever null becomes nullable (| null, *T, Optional[…]).
- Numbers
- Integers and floats are separated for Go (int / float64) and Python (int / float).
- Mixed types
- A field with conflicting kinds across samples falls back to any / interface{} / Any.
Frequently asked questions
Which output formats are supported?+
TypeScript interfaces, a Zod schema (which also exports an inferred TypeScript type), Go structs with JSON struct tags, Python dataclasses, Kotlin data classes, and Java — either records (no dependencies) or Lombok @Data classes. More can be added on request.
Java records or Lombok — what is the difference?+
The record output is plain modern Java (Java 16+) with no dependencies: immutable components, ideal with Jackson. The Lombok output is a mutable class annotated @Data, so getters, setters, equals, hashCode, and toString are generated at compile time. Both use boxed types (Long, Double, Boolean) so any field can be null.
How are optional and nullable fields decided?+
Give it an array of objects and it merges them: a key that appears in only some elements is marked optional, and a value that is null in any sample makes the field nullable. A single object has no basis for optionality, so all its fields are required.
Is my JSON uploaded anywhere?+
No. Parsing and code generation happen entirely in your browser with client-side JavaScript. Nothing is sent to a server — safe for real API responses.
Why did a field become “any”?+
When the same field holds fundamentally different kinds across samples (for example a string in one object and an object in another), there is no single type to infer, so it degrades to the language’s catch-all (any, interface{}, or Any) rather than guessing.
Does it handle a top-level array?+
Yes. It generates a type for the element and a root alias — for example an interface plus “type Root = RootItem[]” in TypeScript.
Can I generate types from a JSON Schema instead of a sample?+
Yes — switch the input mode to “JSON Schema”. It reads properties, uses the “required” list to mark optional fields, treats a "null" type as nullable, and resolves local “$ref” definitions ($defs/definitions) into shared named types. Combinators like allOf/anyOf/oneOf aren’t unified yet and fall back to the catch-all type.
Works well with
JSON to Types chains with these tools — send your result straight on:
Related tools
Code Formatter
Format and beautify JSON, YAML, TOML, XML, HTML, and CSS — with JSON/CSS minify and JSON schema validation.
Data Diff
Compare two JSON, YAML, or TOML documents by structure, not text: added, removed, and changed values with their paths. Key order and formatting are ignored. Runs in your browser.
HAR Viewer
Open a .har network export and explore its requests, sizes, status codes, and a timing waterfall — entirely in your browser. Nothing is uploaded.
JSON ↔ YAML ↔ TOML
Convert structured data between JSON, YAML, and TOML, live in your browser.
JSON to SQL
Infer a SQL CREATE TABLE from a JSON sample or a JSON Schema — column types, nullability, and a primary-key guess — for PostgreSQL, MySQL, or SQLite. Runs in your browser.
JSONPath Tester
Query JSON live with JSONPath — filter, slice, and recurse, and see each matched value with its path, all in your browser.