Skip to main content
appkiro.com

从 JSON 生成 JSON Schema

根据已观察的 payload 生成 JSON Schema 草稿,并选择与 validator 或 API 工具链兼容的 dialect。 单个示例不能代表完整合同。

直接回答

JSON Schema 用于描述 JSON 文档允许的结构、类型和约束。 AppKiro 可从示例推断并提供多个 draft,但 optional、union、format 与业务规则仍需人工补充。

选择 dialect,生成基础 schema,并用目标 validator 验证。

1

输入 JSON

已载入示例 JSON。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2

输出 JSON Schema

1{2  "$schema": "http://json-schema.org/draft-07/schema#",3  "type": "object",4  "properties": {5    "user": {6      "type": "object",7      "properties": {8        "id": {9          "type": "integer",10          "examples": [11            112          ],13          "description": "Id field."14        },15        "name": {16          "type": "string",17          "examples": [18            "John"19          ],20          "description": "Name field."21        },22        "email": {23          "type": "string",24          "format": "email",25          "examples": [26            "[email protected]"27          ],28          "description": "Email field."29        },30        "isActive": {31          "type": "boolean",32          "examples": [33            true34          ],35          "description": "IsActive field."36        },37        "roles": {38          "type": "array",39          "items": {40            "anyOf": [41              {42                "type": "string",43                "examples": [44                  "admin"45                ]46              },47              {48                "type": "string",49                "examples": [50                  "editor"51                ]52              }53            ]54          },55          "examples": [56            [57              "admin",58              "editor"59            ]60          ],61          "description": "Roles field."62        },63        "profile": {64          "type": "object",65          "properties": {66            "age": {67              "type": "integer",68              "examples": [69                3070              ],71              "description": "Age field."72            },73            "address": {74              "type": "object",75              "properties": {76                "city": {77                  "type": "string",78                  "examples": [79                    "New York"80                  ],81                  "description": "City field."82                },83                "zip": {84                  "type": "string",85                  "examples": [86                    "10001"87                  ],88                  "description": "Zip field."89                }90              },91              "required": [92                "city",93                "zip"94              ],95              "description": "Address field."96            }97          },98          "required": [99            "age",100            "address"101          ],102          "description": "Profile field."103        },104        "lastLogin": {105          "type": "string",106          "format": "date-time",107          "examples": [108            "2024-03-18T10:24:00Z"109          ],110          "description": "LastLogin field."111        },112        "homepage": {113          "type": "string",114          "format": "uri",115          "examples": [116            "https://example.com"117          ],118          "description": "Homepage field."119        }120      },121      "required": [122        "id",123        "name",124        "email",125        "isActive",126        "roles",127        "profile",128        "lastLogin",129        "homepage"130      ],131      "description": "User field."132    }133  },134  "required": [135    "user"136  ]137}

使用方法

  1. 粘贴/上传 JSON,或打开受支持的公开示例。
  2. 选择 Draft 4、6、7、2019-09 或 2020-12,并设置 type mapping、required、description、examples、const、null 和字段顺序。
  3. 在目标 validator 中检查 raw/tree 输出,再按真实数据完善 schema。

主要功能与设置

  • 当前界面可选 Draft 4 至 2020-12。
  • 控制 type mapping、description 和 examples。
  • 设置 required、const 与 null 处理。
  • 提供 raw/tree 预览、复制和下载。

支持的输入与输出

输入: JSON 文本或文件, 受支持的公开 URL. 输出: JSON Schema 文本或文件.

适用场景

  • 为 API payload 创建 schema 起点。
  • 记录配置文件或事件结构。
  • 在集成 validator 前比较不同 dialect。

应该选择哪种工作流?

需要“当前界面可选 Draft 4 至 2020-12。 ”时使用 JSON Schema 生成器;需要“当前界面目标包括 OpenAI、Claude 与 Gemini。 ”时使用 Function Calling Schema 生成器。

隐私与数据路径

当前实现中,粘贴/上传内容在浏览器内处理;“Extract from URL”会通过服务器代理获取来源。

限制与故障排查

  • OpenAPI 3.1 使用 JSON Schema Draft 2020-12 语义;请选择下游工具链明确支持的 dialect。
  • 单样本无法揭示 optional property、全部 union、format 和值域约束。
  • 当前界面显示 5 MB 输入限制。

FAQ

应该选择哪个 JSON Schema draft?

选择 validator、OpenAPI 工具与 schema 使用方明确支持的 dialect。 新建独立项目可优先评估 2020-12,但仍必须验证兼容性。

数据会上传到服务器吗?

当前实现中,粘贴/上传内容在浏览器内处理;“Extract from URL”会通过服务器代理获取来源。

文件或数据大小有什么限制?

当前界面显示 5 MB 输入限制。

可以在手机上使用吗?

该页面是网页工具,可能可在现代移动浏览器中运行,但文件选择、内存占用和跨设备兼容性尚未在所有设备上验证。 较大或复杂输入建议使用桌面浏览器。

应该选择哪种工作流?

需要“当前界面可选 Draft 4 至 2020-12。 ”时使用 JSON Schema 生成器;需要“当前界面目标包括 OpenAI、Claude 与 Gemini。 ”时使用 Function Calling Schema 生成器。

相关工具

选择 dialect,生成基础 schema,并用目标 validator 验证。