JSON 转 Schema 博客 打开工具 →

JSON Schema 嵌套对象定义指南

嵌套对象就是把 properties 一层层写进去。关键点是「每一层对象都有自己的 type/properties/required」。

更新于 2026-08-30 · 阅读约 4 分钟

两层嵌套

{
  "type": "object",
  "properties": {
    "user": {
      "type": "object",
      "properties": {
        "name": { "type": "string" },
        "address": {
          "type": "object",
          "properties": {
            "city": { "type": "string" },
            "zip": { "type": "string" }
          },
          "required": ["city", "zip"]
        }
      },
      "required": ["name", "address"]
    }
  },
  "required": ["user"]
}

对应 JSON:

{
  "user": {
    "name": "Ada",
    "address": { "city": "London", "zip": "EC1" }
  }
}

数组里的对象嵌套

当数组元素是对象时,items 里再放一层 properties。如果数组里每个对象的字段不完全一致,工具会把多个对象出现过的 key 合并,未在所有对象里出现的字段不计入 required

小技巧

👉 打开工具,粘入你的嵌套 JSON,自动展开多层 properties