JSON to Code
Generate TypeScript, Go, Python, Java, Kotlin, Rust, C#, or PHP types from JSON.
JSON input
Generated code
Enter JSON on the left to generate a type from it.
What is JSON to Code?
A JSON to Code generator inspects a JSON document's actual shape — its keys, nesting, and value types — and produces a matching type definition in a programming language of your choice: a TypeScript interface, a Go struct, a Python TypedDict, a Java record, a Kotlin data class, a Rust struct, a C# record, or a PHP class. This saves the tedious, error-prone step of hand-transcribing an API response or config file into typed code every time the shape of that data changes. Rather than writing (and constantly re-writing) type definitions by hand whenever an upstream JSON payload gains a field or changes a value's type, you paste the JSON once and get an accurate starting point in the target language, with nested objects and arrays turned into their own named types. Each language gets its own idiomatic syntax for a key that's missing from some array elements — a `?` in TypeScript, `NotRequired[...]` in a Python TypedDict, an `omitempty` struct tag in Go, `Option<T>` in Rust — and, except in TypeScript, a number is typed as an integer or a float per value, based on whether that exact sample has a decimal point.
How to use JSON to Code
- Paste or type a representative JSON document into the left panel — the more complete the sample (all optional fields present, arrays with at least one item), the more complete the generated type will be.
- Pick a target language from the dropdown above the output — TypeScript, Go, Python, Java, Kotlin, Rust, C#, or PHP.
- Optionally set a root type name (defaults to "Root") — nested object types are named after the key that contains them.
- Copy the generated code from the right panel directly into your project.
Examples
Flat object → TypeScript
Input
{"id": 1, "name": "Ada", "active": true}
Output
type Root = { id: number name: string active: boolean }
Nested object → Go struct
Input
{"user": {"id": 1, "name": "Ada"}}
Output
type User struct { Id int64 `json:"id"` Name string `json:"name"` } type Root struct { User User `json:"user"` }
Per-value int vs. float inference → Go (int64 vs. float64; TypeScript would type both as number)
Input
{"id": 1, "price": 9.99}
Output
type Root struct { Id int64 `json:"id"` Price float64 `json:"price"` }
Common mistakes
- Pasting a JSON sample that's missing optional fields — the generated type will simply omit fields it never saw, so an incomplete sample produces an incomplete type.
- Assuming every language treats numbers as generically as TypeScript's `number` — the rest infer int vs. float per value from the sample itself, so a whole-number sample like 5 generates an integer type even for a field that's a float in production; include a decimal example if that's what you need, and expect a generic placeholder instead of a clean type if the same key mixes an integer and a decimal across array elements.
- Forgetting to rename the root type — if you're generating multiple related types in the same file, give each generation a distinct root name to avoid a naming collision.
- Assuming the array-element merge only looks at the first item — every element's shape is merged, so a key present on only one of many elements still appears, marked optional, which can produce a wider type than a single-item glance would suggest.
Why use this tool
- Runs entirely client-side — no JSON you paste here is ever sent to a server.
- Covers eight languages from one input, so you don't need a separate tool per target language.
- Nested objects and arrays get properly named sub-types instead of being flattened or left untyped.
- Merges every array element's shape into one type instead of reading just the first item, so a field present on only some elements is still captured as an optional field rather than silently dropped.