gitmyhub

quicktype

TypeScript ★ 14k updated 7mo ago

Generate types and converters from JSON, Schema, and GraphQL

Reads JSON, JSON Schema, or API responses and automatically generates type-safe data classes and parsing code in over 20 languages including Python, Go, Swift, Kotlin, Rust, and TypeScript.

TypeScriptJavaScriptnpmsetup: easycomplexity 2/5

quicktype is a tool that reads JSON data and automatically writes the type definitions and parsing code you would normally write by hand. When a program receives JSON from an API, a developer typically needs to define classes or structs that match the JSON structure, then write code to convert between raw JSON text and those typed objects. quicktype does this generation automatically for more than 20 programming languages.

You give quicktype a JSON file, a live API URL, a JSON Schema, a TypeScript definition, or a GraphQL query. It analyzes the structure and outputs ready-to-use code in whatever target language you choose. Supported output languages include Python, Go, Swift, Kotlin, Rust, Java, C#, C++, TypeScript, Dart, Scala, Ruby, Elm, Haskell, PHP, and several others. The generated code includes both the type definitions and the serialization and deserialization logic, so you can immediately read and write JSON in a type-safe way.

A web interface at app.quicktype.io lets you paste or load JSON and see the generated code in any supported language without installing anything. The tool also works as a command-line program installed via npm, and as a JavaScript library you can call from your own build scripts.

The recommended workflow for larger projects is to first generate a JSON Schema from your sample data, review and edit that schema to make it accurate, check it into your version control system, and then generate code from the schema during your build process. This way the schema becomes the single source of truth, and you can regenerate models for every language in your stack from the same definition.

The project is open source. It is maintained under the quicktype GitHub organization, and community contributions adding new target languages are welcome per the README.

Where it fits