Infer JSON Schema 从样本数据
生成 a JSON Schema that describes the structure of a JSON instance, for validation and documentation.
- 1
JSON 模式 describes shape 的 JSON 数据 — 需要 fields, types, formats, constraints. Inferring 模式从 样本数据 gives 你 validation 契约和 文档无 hand-writing 模式.
- 2 JSON Schema 生成器 →
Paste JSON 实例 (ideally 具有所有 fields populated). tool infers types, 需要 properties, 数组项 types, 和 emits JSON Schema (draft 2020-12).
- 3 JSON 验证器 →
验证 other instances against the generated schema to confirm they conform. Mismatches reveal fields that are missing, extra, or wrong-typed.
常见问题
- 模式是 too permissive — 如何 I 添加 constraints?
- Inferred schemas capture observed types 但不 business rules. Manually 添加 constraints: 字符串格式化 (日期-时间, email), 数字最小值/最大值, 字符串 minLength/maxLength, enum values, 和 additionalProperties: 假到 拒绝 unknown fields.
- 应该 I infer 从 one 样本或 许多?
- 许多. 单个样本 misses 可选 fields (fields 不存在在 该实例成为需要) 和联合 types ( 字段该 是有时空). Provide 多个 instances 或 manually mark fields 可选之后推理.