JSON → JSON Schema
从 JSON 样本生成 draft 2020-12 或 draft-07 风格的 JSON Schema,包含 $schema、type、properties、items、required 与 additionalProperties,混合数组使用 items.anyOf。
输入与参数
input— JSON 输入title— Schema 标题dialect— 方言requireAll— 样本中所有键都列为 required
真实示例
{"id":1,"active":true,"deleted":null,"tags":["a",2]}
→ {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Root",
"type": "object",
"properties": {
"id": { "type": "integer" },
"active": { "type": "boolean" },
"deleted": { "type": "null" },
"tags": { "type": "array", "items": { "anyOf": [{ "type": "string" }, { "type": "integer" }] } }
},
"additionalProperties": false,
"required": ["id", "active", "deleted", "tags"]
}
限制与失败处理
样本推导不推断 format、enum、minimum、pattern 等约束;additionalProperties:false 是保守的样本形状选择,可能拒绝未来新增字段;空数组的 items 特意留空对象并附说明。大整数标注 integer 且带精度策略注释,不声称无损。
FAQ
draft-07 与 2020-12 有何差异?
本站只切换 $schema URI;其余 type/properties/items/anyOf/required/additionalProperties 结构相同,均在输出与说明中标注所选方言。
required 为什么默认全列?
因为单个样本无法区分「必填」与「恰好存在」;默认把样本所有键列为 required,取消勾选则不生成 required 数组,绝不猜测。
能校验任意实例吗?
本站只生成 Schema 文本,不内置校验器;请把 .schema.json 下载后交给你的 draft 兼容校验器使用。