How to use
- Paste your JSON into the left box, or press Load example. The code appears on the right as you type.
- Choose the language, and the name of the top-level type. Leave Types only on for plain type definitions, or switch it off to also get the code that reads and writes JSON.
- Copy the code or download it as a file with the right ending, such as Root.ts or Root.go.
Examples
{"id":1,"name":"Kit","tags":["a","b"]}, TypeScript→ export interface Root { id: number; name: string; tags: string[]; }The real output is laid out over several lines with the names lined up.The same JSON, Go
→ type Root struct { ID int64 `json:"id"`; Name string `json:"name"`; Tags []string `json:"tags"` }Go gets the json tags it needs to read the field names.The same JSON, Python
→ @dataclass class Root: id: int; name: str; tags: list[str]Tick Pydantic to get Pydantic models instead of dataclasses.
How it works
The code is generated by the open-source quicktype library, the engine behind the quicktype website. It reads the sample, works out one type for every kind of object it finds, merges the objects in a list into one type, marks fields that are missing in some of them as optional, and then writes the types in the style of the chosen language. quicktype loads only when you start a conversion, because it is large.
Names of types come from the keys: a key called owner holds an object that becomes a type called Owner. The top-level type takes the name you give it, cleaned so that it is a valid name.
The tool is tested with a sample for every language on the list, which must produce code, and with checks of the TypeScript, Go, Python, Rust, Kotlin, C#, Swift, Zod and JSON Schema output, optional fields, lists at the top level and the options.
Sources
- quicktype, the open-source library that generates the code
- JSON Schema
- TypeScript handbook: Object types
Frequently asked questions
- How do I convert JSON to a TypeScript interface?
- Paste the JSON, keep TypeScript chosen, and copy the result. Nested objects become their own interfaces, lists become arrays, and a field that is missing in some items of a list becomes optional (marked with ?).
- Why is a field typed as null or any?
- The tool can only know what the sample shows. A field that is null in your sample has no known type, and an empty list has no known item type. Use a sample where those fields have real values, or edit the type by hand.
- Are dates turned into Date types?
- Not unless you tick Detect dates. JSON has no date type, so a date is a string when it is parsed. Typing it as Date would be wrong until you convert it, so strings stay strings by default.
- What does Types only do?
- With it on, you get just the type definitions. With it off, you also get the helper code that converts between JSON text and the types, which is longer and depends on libraries in some languages.
- Which languages are supported?
- TypeScript, TypeScript with Zod schemas, Python, Go, Java, Kotlin, Swift, C#, Rust, Dart, PHP, Ruby, C++, Objective-C, Scala 3, Elm, Haskell and JSON Schema.
- Is my JSON sent anywhere?
- No. The code is generated in your browser. The conversion library is large, so it loads the first time you convert.
Related tools
Version history
- 1.0.1 — Clarifies the search title with the tool's main task and whether it is free or runs online.
- 1.0.0 — First release.