JSON 转 Schema 博客 打开工具 →

JSON 转 Go struct 思路

JSON Schema 是语言无关的中间表示。拿到 Schema 后,按 Go 的类型规则映射一遍,就能得到 struct。

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

类型映射表

JSON SchemaGo 类型
stringstring
integerint64
numberfloat64
booleanbool
objectstruct { … }
array[]T(T 为元素类型)
null*T 或 interface{}

示例

Schema(来自工具生成):

{
  "type": "object",
  "properties": {
    "name": { "type": "string" },
    "age": { "type": "integer" },
    "tags": { "type": "array", "items": { "type": "string" } }
  },
  "required": ["name", "age", "tags"]
}

对应 Go struct:

type User struct {
  Name string   `json:"name"`
  Age  int64    `json:"age"`
  Tags []string `json:"tags"`
}

注意

👉 打开工具先把 JSON 转成 Schema,再按表映射成 struct