Mock JSON Generator

One input per line. Output is numbered to match the input order.
Pinned tools are listed in your favourites on the home page.Copies a link to this tool that carries your current input, so it opens ready to run.Gives you an iframe snippet for putting this tool on your own site.
JSON Schema
Generated Output
Ctrl+Enter Run  · Ctrl+Shift+C Copy  · Esc Clear

Understand Mock JSON Generator

按照你粘贴进来的 JSON Schema 生成示例 JSON 记录。

How it works

schema 会被递归遍历:每种 type 产出对应类型的值,format 提示决定贴近真实的形态(uuid 使用 crypto.randomUUID,另有 email、name、date 和 uri),minimum 和 maximum 约束数字,minLength 和 maxLength 约束字符串,enum 从所列值中挑一个,minItems 和 maxItems 决定数组长度。对象沿 properties 递归,因此嵌套结构会与 schema 描述的形状一致。每次运行最多 50 条记录。

When to use it

  • 在后端 API 尚不存在时,为前端产出真实的响应体。
  • 用你已经在维护的 schema 为 Storybook story 或测试数据库填充数据。
  • 生成一个各字段都处于 schema 允许最大长度的载荷,看 UI 如何应对。
  • 交给设计师符合真实契约、而不是凭空编造字段的示例数据。
  • 检查消费方能否处理空数组或缺失的可选字段。

Watch out for

  • 本工具按 schema 生成数据,而不是用 schema 做校验。即便 schema 本身是错的,它也会照样产出数据——当问题在于 schema 是否正确时,请使用 JSON Schema 校验器。
  • 只支持 JSON Schema 的一部分:type、format、enum、minimum、maximum、minLength、maxLength、minItems、maxItems、properties 和 items。required、$ref、oneOf、allOf、pattern 和 additionalProperties 会被忽略,因此依赖它们的 schema 可能产出被你真实校验器拒绝的数据。
  • 除 format: uuid 之外,值都来自 Math.random。这对夹具没问题,但输出在多次运行之间不可复现,也绝不可用于需要让攻击者无法预测的场合。
  • 不带 format 的普通字符串是随机的 36 进制噪声,不是词语。当截图或演示需要可读的值时,请加上 format: name、format: email 或一个 enum。

Not the right tool for: 压测量级的大批量数据。上限是每次运行 50 条记录;当你需要几万行时,请针对你的 schema 编写生成脚本。

Frequently Asked Questions

如何生成一个对象数组?

把 schema 的 type 设为 array,并带上 items 对象:{"type":"array","items":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"name":{"type":"string"}}}}。用 minItems/maxItems 控制数组长度。

有哪些 format 提示可用?

用 format 可以得到贴近真实的值:"email" → [email protected],"uuid" → UUID v4,"date" → ISO 日期,"url" → https 链接,"name" → 姓名全称,"phone" → 电话号码。它们比随机字符串更进一步,能产出可信的测试数据。

可以用它做 API 测试夹具吗?

可以——把 API 响应的 schema 定义一次,就能生成几十条测试记录。可导出为 JSON 数组,用于填充开发数据库、构建 Postman 集合,或供自动化测试套件使用。

How to Use Mock JSON Generator

  1. Paste or type your input in the input area above.
  2. The tool processes your input automatically or click Run.
  3. Copy or download the result using the action buttons.
  4. Use Ctrl+Enter to run quickly from the keyboard.