# Quicktype — Generate Type-Safe Code from JSON, Schema, and GraphQL > An open-source tool that generates strongly-typed models and serializers for 20+ languages from JSON samples, JSON Schema, TypeScript interfaces, and GraphQL queries. ## Install Save in your project root: # Quicktype — Generate Type-Safe Code from JSON, Schema, and GraphQL ## Quick Use ```bash npm install -g quicktype # Generate TypeScript types from a JSON sample quicktype -s json -o Types.ts sample.json # Generate Go structs from a JSON Schema quicktype -s schema -l go -o types.go schema.json ``` ## Introduction Quicktype generates strongly-typed data models and serialization code from JSON samples, JSON Schema, TypeScript interfaces, and GraphQL queries. It supports over 20 target languages including TypeScript, Python, Go, Rust, Swift, Kotlin, C#, and Java. The tool eliminates manual type definition work and ensures your code matches the actual shape of API responses and data files. ## What Quicktype Does - Infers types from JSON samples and produces strongly-typed models in 20+ languages - Reads JSON Schema, TypeScript interfaces, and GraphQL queries as input sources - Generates marshaling and unmarshaling code for safe JSON serialization - Merges multiple JSON samples to infer union types and optional fields - Provides a CLI, a Node.js library, and a web playground at app.quicktype.io ## Architecture Overview Quicktype works in three phases. First, an input processor parses JSON samples, JSON Schema, TypeScript, or GraphQL into an intermediate representation (IR) of types. Second, an optimization pass simplifies the IR by merging equivalent types, detecting enums, and resolving union types. Third, a language-specific renderer converts the IR into source code with proper naming conventions, imports, and serialization logic for the target language. Each target language has its own renderer plugin, making the system extensible. ## Self-Hosting & Configuration - Install globally: `npm install -g quicktype` - Use as a library: `npm install quicktype-core` for programmatic access - Specify input source with `-s` flag: `json`, `schema`, `typescript`, or `graphql` - Choose target language with `-l` flag: `typescript`, `python`, `go`, `rust`, `swift`, etc. - Pipe JSON directly: `curl api.example.com/data | quicktype -l python` ## Key Features - Supports 20+ output languages with idiomatic naming and serialization patterns - Infers optional fields, enums, and union types from multiple JSON samples - Generates runtime validation and conversion helpers alongside type definitions - Web playground at app.quicktype.io for quick experimentation without installing anything - Extensible architecture allows adding new input formats and target languages ## Comparison with Similar Tools - **json2ts / json-to-ts** — TypeScript only; Quicktype supports 20+ languages from the same input - **OpenAPI Generator** — generates client SDKs from OpenAPI specs; Quicktype focuses on raw JSON/Schema to types without needing an API spec - **Typebox** — defines TypeScript types that double as JSON Schema; Quicktype goes the other direction, from data to code - **datamodel-code-generator** — Python-focused code generation from JSON Schema; Quicktype covers many more target languages - **gRPC / Protobuf** — requires defining .proto files upfront; Quicktype infers structure from existing JSON data ## FAQ **Q: Can Quicktype handle deeply nested JSON?** A: Yes. It recursively infers types for nested objects and arrays, generating corresponding nested classes or structs. **Q: How does it handle fields that are sometimes null?** A: It marks those fields as optional (nullable) in the generated types and adds appropriate null-handling in serialization code. **Q: Can I customize the generated code style?** A: Yes. CLI flags control naming conventions, access modifiers, and whether to generate helper functions or just types. **Q: Is it accurate with complex JSON?** A: Providing multiple JSON samples improves accuracy. Quicktype merges samples to build a comprehensive type that covers all observed variations. ## Sources - https://github.com/glideapps/quicktype - https://app.quicktype.io --- Source: https://tokrepo.com/en/workflows/asset-b20dac54 Author: AI Open Source