JSON to Type Definitions
Generate TypeScript, Go, Rust, C#, Python and more from sample JSON. Powered by quicktype, lazy-loaded only on this page.
About the JSON to Type Definitions
JSON to Type Definitions turns a sample JSON payload into typed structs and interfaces for your language. When you get an API response but no schema, you end up hand-writing types field by field and guessing whether a number is an int or a float. Paste the response, pick a target language, and get a matching type definition to drop into your codebase.
The tool reads the JSON in the sample box, checks it parses with JSON.parse, then feeds it to quicktype using the root name you set. quicktype walks the structure and infers a type for every field, giving nested objects and arrays their own named types. It renders types only, no serializers or helper methods, and the engine is lazy-loaded the first time you press Generate.
It infers the type definitions in the browser as you paste JSON, so no signup is needed. Everything runs in your browser: your JSON is parsed and converted on your own machine and never uploaded. That matters when the sample is a real production response with customer emails or internal IDs. You can generate unlimited types, switch between eight targets, and copy with one button.
How to use the JSON to Type Definitions
- 1Paste or type your JSON into the JSON sample box, replacing the example payload that loads by default.
- 2Set the Root type name field to name the top-level type; only letters, digits, and underscores are kept.
- 3Click a target button to choose TypeScript, Go, Rust, C#, Python, Kotlin, Swift, or JSON Schema.
- 4Press Generate and wait for the button to finish its Working state.
- 5Read the generated declarations in the output box, then click Copy.
- 6If a red error appears, fix the reported JSON syntax problem and press Generate again.
What you can use it for
Typing an undocumented API
You hit a third-party endpoint that returns JSON but ships no schema. Paste one real response, generate a TypeScript interface, and you have accurate field names and types for your client code without reading the payload key by key.
Porting a payload to Go
You are moving a service to Go and need structs for an existing JSON contract. Generate Go types from a sample and get the nested structs and slice types laid out so you can wire up encoding/json against the real shape.
Producing a JSON Schema
You need a JSON Schema to validate incoming data or document a contract. Choose the JSON Schema target and the tool infers a schema from your sample, giving you a draft you can tighten by hand.
Why a single sample shapes the types
quicktype infers structure from the values you give it, and here it sees exactly one sample. If active is true it infers a boolean; if id is 7 it infers an integer. Because there is one example, every key that appears is treated as always present. quicktype cannot know a field is sometimes absent, sometimes a string and sometimes a number, or occasionally null.
That is why the safest input is a payload that exercises the real variety of the data. An empty array gives quicktype nothing to infer an element type from, and a null field carries no type information. When the contract allows optional or nullable fields, loosen those fields by hand before you commit the types.
Frequently asked questions
Is my JSON sent anywhere?
No. The tool is a client-side component, so both the JSON.parse validation and the quicktype conversion happen in your browser. Nothing is uploaded, so you can paste real responses with private data such as emails or internal identifiers safely.
Which languages can it output?
Eight targets: TypeScript, Go, Rust, C#, Python, Kotlin, Swift, and JSON Schema. Click a target button before generating, and the output box is labeled with the language you chose. Switch targets and regenerate as often as you like.
Why did I get an error instead of types?
The tool runs JSON.parse before converting, so invalid JSON stops it and shows the parser's message in red. Trailing commas, single quotes, unquoted keys, or a stray bracket all trigger this. Fix the syntax and press Generate again.
Does it produce serialization code too?
No. It runs quicktype with just-types enabled, so you get only the declarations, structs, interfaces, or schema, with no marshalling functions or decoders. That keeps the output short, but you supply your own encoding logic.
What happens to my root type name?
The Root type name field strips any character that is not a letter, digit, or underscore as you type, and falls back to Root if you clear it. That name becomes the top-level type; nested types are named by quicktype.
Can I feed it more than one sample?
No, the box takes a single JSON document. quicktype infers types from that one example, so a field present in your sample becomes required. If real data sometimes omits a key or sends null, the type will not mark it optional.