Docs / Editing tools
Type generation
Last updated:
Generate Types turns a JSON or YAML document into type definitions for your code. It is powered by quicktype and runs on your device. Type generation is free in Prettify.
Generate types from your data
Load a JSON or YAML document, then open the tool.
- Load JSON or YAML in the editor.
- Click Generate Types in the toolbar, under the Transform group.
- Pick a target language from the tabs.
- Copy the result, or download it as a file.
You can also open the Command Palette with Cmd+K (Mac) / Ctrl+K (Windows, Linux) and choose Generate Types. The tool reads the current document, so the types match the data you see.
Target languages
Prettify generates these targets. The download file uses the extension shown.
| Target | File extension |
|---|---|
| TypeScript | .ts |
| Go | .go |
| Kotlin | .kt |
| Rust | .rs |
| JSON Schema | .schema.json |
Each target uses idiomatic defaults.
- TypeScript: interfaces only, with no runtime helpers.
- Go: structs with
jsonfield tags and a package declaration. - Rust: structs that derive serde
SerializeandDeserialize, plusDebugandClone. - Kotlin: data classes.
- JSON Schema: a schema that describes the sample.
Name the root type
The Root type field sets the name of the top-level type. Prettify fills it from the document or tab name, and you can edit it. A name that starts with a digit gets a Type prefix, and an empty name becomes Root.
Notes
Generate Types works on JSON and YAML only. The tool infers types from one sample, so a wider sample gives more accurate optional fields and unions. Large or high-precision numbers are passed to quicktype as valid JSON numbers.
Related
Try it online
Tool pages for this topic. Each one runs in your browser.