JSON Schema Generator

Paste a sample document and get a JSON Schema describing it, in Draft-07 or 2020-12. Nested objects and arrays are handled, array item types are inferred from the contents, and a mixed array collapses to a simple type list rather than a verbose anyOf when it can. Two choices here are worth knowing because they are opinionated. Whole numbers come out as `integer` rather than `number`, since that is what a validator enforces and what your sample actually shows — widening it later is one word. And every key present is marked required, because one sample cannot possibly tell you which fields are optional; it is much easier to delete entries from `required` than to notice which keys simply did not happen to appear in the example you had. Treat the result as a very good first draft rather than a finished contract. Nothing is uploaded.

How a sample maps to schema

Sample valueInferred
1{"type": "integer"}
1.5{"type": "number"}
"a"{"type": "string"}
null{"type": "null"}
["a","b"]array of {"type": "string"}
[1,"a"]{"type": ["integer","string"]}
[]{"type": "array"} — nothing to infer

When to use it

  1. Bootstrap a schema for an API you are documenting.
  2. Add validation to a config file you already have examples of.
  3. Generate a contract for a payload before writing a test against it.
  4. Check what types a sample actually contains.
  5. Start a schema for a third-party response you do not control.

How to Use

  1. Paste a representative sample document.
  2. Choose Draft-07 or 2020-12.
  3. Copy the schema, then trim `required` and widen any types as needed.

Features

  1. Draft-07 and 2020-12 output
  2. Integer distinguished from number
  3. Nested objects and arrays at any depth
  4. Array item types inferred and de-duplicated
  5. Mixed simple types collapsed to a type list
  6. Empty arrays left open rather than guessed
  7. 100% client-side

FAQs

Is my sample uploaded?

No. It is parsed and converted in your browser.

Why is everything marked required?

Because one sample cannot show what is optional — a field simply not appearing in your example does not mean it is not mandatory. Marking everything required and letting you delete what is optional is safer than the reverse, where an omission silently becomes permission.

Why integer instead of number?

Because it is the stricter and more informative reading of what you pasted, and it is a distinction validators enforce. If the field can also hold 1.5, change that one word. Starting loose would hide a real constraint.

How are mixed arrays handled?

If every item is a simple type, they collapse into a type list such as ["integer","string"], which is shorter and what a person would write. If the alternatives are structured objects that genuinely differ, anyOf is used instead.

What about an empty array?

It is typed as an array with no items constraint, because there is nothing in it to infer from. Guessing would be worse than leaving it open.

Which draft should I choose?

Draft-07 has the widest library support and is the safe default. Choose 2020-12 if your validator specifically expects it — for schemas this simple the only difference in the output is the $schema identifier.

Technical Details

A sample document is walked and each value turned into the schema fragment that describes it, recursing through objects and arrays. Two decisions shape the output and both are deliberate. Whole numbers are typed as `integer` rather than `number`, because that is a distinction a validator will actually enforce and one a sample can genuinely demonstrate; widening it afterwards is a one-word edit, whereas discovering later that a field was silently permitted to hold 1.5 is a bug. Every key present is listed as required, because a single sample cannot show which fields are optional — absence of evidence is not evidence of optionality — and deleting entries from `required` is far easier than working out which keys happened not to appear in the example you pasted. Arrays infer their item schema from their contents, and a heterogeneous array collapses to a single type list such as `["integer","string"]` when every candidate is a simple type, since that is shorter and is what a person would have written by hand; `anyOf` is used only when the alternatives are structured and genuinely cannot be collapsed. Duplicate candidate schemas are merged, so an array of a thousand identically-shaped objects produces one item schema rather than a thousand. An empty array is left as `{"type":"array"}` with no items rather than guessing at what it might hold. Draft-07 and 2020-12 are both offered, differing in the `$schema` identifier. The sample never leaves your browser.

Developer Tools

Developer Tools

  • License Generator
  • Nanoid Generator
  • Random String Generator
  • Test IBAN Generator
  • UUID Generator
  • Regex Tester
  • Cron Parser
  • JSON to TypeScript