JSON Schema Generator: Infer a Schema from Samples
Paste one or more JSON samples to infer a Draft-07 schema. Fields seen on every object become required, disagreeing types are merged, and arrays, small enums, and optional email or date-time formats are detected. The result is inferred from those samples, not an authoritative schema. This page does not fetch the $schema URL, and it does not validate instances against a schema you already wrote.
Each box holds one JSON value, or several values separated by whitespace. A JSON array stays an array unless you merge its elements below.
Paste JSON, or load the example.
What this inference decided
The schema below is inferred, not an authoritative contract. $schema is only the Draft-07 name; this tool does not fetch that URL. It also does not check JSON against a schema you supply.
How this inference works
- The schema is inferred from the samples you paste. It is a starting point for those samples, not an authoritative contract for data you have not shown.
$schemais set to the Draft-07 identifierhttp://json-schema.org/draft-07/schema#. That string names the dialect. This tool does not fetch, download, or request that URL, and it works offline.- This tool does not validate JSON instances against a schema you supply. It only builds a schema from samples.
- A field is required when that key is present on every object of that shape. A value of null still counts as present, and null is its own type. A key missing from any of those objects is optional. With one object sample, every key looks required.
- When values disagree, their types are merged. Integers and other numbers collapse to
number, because every JSON integer is a number. Other mixes use a type array in this fixed order: null, boolean, integer, number, string, array, object. Whole numbers inside JavaScript’s safe integer range, including values such as 1.0, areinteger. Larger whole numbers arenumber, because parsing may have rounded them. - Object keys stay in the order they first appeared. Later samples append new keys at the end. Required lists follow that same order.
- Arrays use one
itemsschema for every element. Draft-07 positional tuples are not inferred. An empty array does not additems, so its elements are not constrained. - Enums copy observed values into the schema, in first-seen order. Strings are enumerated when there are at least two distinct strings and no more than the limit you set. Null may sit in that set. Numbers are enumerated only when every value is a number and at least one number repeats, so a few different ids do not become an enum. Booleans, objects, arrays, mixed types, and strings longer than 40 characters are not enums. A field whose strings all match email or date-time is not an enum either.
- String formats are optional. When the checkbox is on,
formatisemailordate-timeonly if every string at that field matches that one format. Date-time means an RFC 3339 date and time with a T, a timezone, and a real calendar date. Email is a practical ASCII check: a local part, a domain with a dot, and a letter TLD. It is not a full RFC 5322 parser, and internationalized addresses are left as plain strings. URI, UUID, date, and time are not detected. In Draft-07,formatis an annotation unless a validator is configured to assert formats. - Extra properties stay allowed unless you turn on the checkbox, which sets
additionalPropertiesto false on every object. Omitting that keyword matches the JSON Schema default. - Top-level array merging is off by default, so a JSON array stays an array. Nested arrays are never unwrapped. An empty top-level array is an error in that mode because it has no element to merge.
- Duplicate keys follow JSON parsing: the last value wins. Comments, trailing commas, and undefined are invalid JSON and produce an error. Nothing is uploaded. Minimum, maximum, string length, pattern, uniqueness, and
$refare not inferred. A box larger than 400 KB, more than 2,000 samples, or nesting deeper than 40 levels is rejected.