Configs2026年5月27日·1 分钟阅读

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.

Agent 就绪

先审查再安装

这个资产需要先审查。复制的指令会要求 Agent dry-run、列出写入项,确认后再继续。

Needs Confirmation · 64/100策略:需确认
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Quicktype
先审查命令
npx -y tokrepo@latest install b20dac54-59a5-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run,确认写入项后再运行此命令。

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

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产