JSON Schema Gen
JSON 样例等待输入
任意官方关键字draft-07 / 2020-12 全量
官方关键字里,patternProperties、if/then/else、dependentSchemas、prefixItems、contains、unevaluatedProperties 等属于结构型约束,按钮无法穷举。这里提供一个根级 JSON 合并入口:写什么就原样并入根 schema,键名不合法会给出提示。
Schema 官方关键字draft-07 / 2020-12
生成选项
输出
结构统计
How to Use
📖 What it does
With enough fields, hand-written schemas drift: a missing key, a wrong type, or an array whose elements do not share a shape. This tool works backwards from a real sample: objects become properties, arrays become items, integers stay separate from decimals, and dates and URLs get their formats.
Inference only uses the sample you provide. Fields that never appear are never invented, so a fuller sample gives a schema closer to the real endpoint.
A 2,000-character sample renders in about 8 ms behind a 150 ms debounce, and even ten levels of nesting take a single recursive pass.
The result is serialized straight to two-space JSON with no intermediate copies, and each recalculation replaces the previous sample reference.
The workspace exposes 15 controls, from $anchor(2020-12) to 识别日期、时间与网址格式, and every one of them only affects the local rendering: nothing is sent back to a server.
Ranges and defaults: additionalProperties (不写入(跟随推断) / false(禁止额外字段) / true(允许额外字段)), 规范版本 (draft-07 / 2020-12). Values outside the slider range are rejected rather than silently clamped.
The $anchor(2020-12) control takes free text and feeds it straight into the preview without sending it anywhere.
The $comment control takes free text and feeds it straight into the preview without sending it anywhere.
The additionalProperties control is a dropdown with the options 不写入(跟随推断) / false(禁止额外字段) / true(允许额外字段); the active option is what the export uses, so check it after every reload.
The title control takes free text and feeds it straight into the preview without sending it anywhere.
The $id control takes free text and feeds it straight into the preview without sending it anywhere.
✨ Features
- Fine-grained types: integer, number, boolean, string, object and array are distinguished instead of flattened to number.
- Array merging: multiple elements are united, and only keys present in every element become required.
- Format detection: ISO dates, date-times and URLs get a format, everything else stays a plain string.
- Dual output: the same structure can be shown as JSON Schema or a TypeScript interface with one tab click.
- Strict objects: additionalProperties defaults to false so undeclared keys fail loudly.
- Clear errors: invalid JSON reports the parse failure instead of emitting half a result.
🚀 How to use
- Paste a real response into the input, keeping double quotes and commas intact.
- Choose whether inferred keys all become required and whether array elements are merged.
- Keep format detection on when the schema feeds documentation, so dates and URLs are annotated.
- Switch the right pane between JSON Schema and TypeScript and check the nesting depth.
- Copy or download, then add defaults, ranges and descriptions for your business rules.
⚠️ Before you rely on it
- The sample decides: keys that never appear are never inferred, and missing keys drop out of required.
- Merging is a union: very different elements collapse into one wide object; disable merging to follow the first element.
- No enums: strings stay strings, so enum values must be added by hand.
- Formats are pattern based: only date, date-time and URL shaped strings are annotated.
- Strict mode bites: additionalProperties: false rejects payloads with extra keys.
- A starting point: no length, range or default constraints are generated.
- Interface language follows the site language setting; there is no in-plugin switch.
- The pasted JSON stays in memory only and is cleared on reload.
Questions people ask: Q: What about fields missing from the sample? A: They are not inferred. Include a response containing them, or add properties and required by hand. Q: Why did array elements merge into one object? A: Merging takes the union, so different shapes collapse into a superset. Disable merging to follow the first element. Q: Can I use it to validate production data? A: As a base, yes, but add length, range and enum constraints, and watch that strict objects reject extra keys. Q: What does a null value in the sample produce? A: The field gets a type array that includes null and is dropped from required, which expresses "may be absent". Q: Why is the array items block empty? A: The sample array was empty, so there was nothing to infer from. Add one realistic element and regenerate to get concrete constraints. Q: Will it handle huge responses? A: Thousands of characters are fine. Past 100,000 the parse and rendering become visible, so sample one record instead.
Typical use: You have a third-party response and need field definitions for the front end. An old project has no types, and one real response should become a TypeScript interface. A public API needs a draft-07 schema that will not embarrass you.
What you can enter: A valid JSON sample is required; objects and arrays both work as the root. Three toggles control required inference, array merging and format detection.
What you get back: A draft-07 JSON Schema or the equivalent TypeScript interface. Structure stats: top-level field count, nesting depth and root type.
Limits to keep in mind: Structure inference only; no enums, ranges, defaults or business meaning. No remote references or $ref splitting; nested structures stay inline. JSON must be valid; nothing is emitted when parsing fails.