Skip to main content

JSON Schema Generator

Infer a Draft 2020-12 JSON Schema from sample JSON

JSON sample

Paste a JSON sample or load an example to generate a schema.

How to use

  1. 1.Paste a JSON sample, upload or drop one .json file, or load an example. An array with several records gives the most accurate result.
  2. 2.The schema updates as you type; inputs over 2 MB wait for Generate schema.
  3. 3.Add an optional title and choose Detect formats, Include examples, Infer required fields and Infer enums.
  4. 4.Read the inference notes for optional, null-only, mixed and enum fields.
  5. 5.Select Validate sample, then copy the schema or download schema.json.

What the JSON Schema Generator does

It reads example JSON and writes a JSON Schema Draft 2020-12 document with the "$schema" URI https://json-schema.org/draft/2020-12/schema. Nested objects become nested properties, arrays get an items schema, whole numbers are typed integer and other numbers number, and nullable fields use a type list such as ["string", "null"]. When an object or array shares a position with other types, the schema uses anyOf with one branch per type, so mixed arrays never break generation.

How the options work

Required fields are the keys present in every object seen at a position, so with an array of records a key missing from one record stays optional. A single object cannot show which keys are optional, and the tool says so. Formats (email, uri, date-time, date, time, uuid, ipv4) are added only when every string at a position matches the same format exactly; turning detection off removes every format keyword. Enums are off by default and are only inferred for repeated, low-cardinality text that is not ID-like, formatted or free text, and they always list every value from the sample.

Validation, limits and privacy

Validate sample compiles the schema with Ajv in Draft 2020-12 strict mode plus ajv-formats and checks your sample, showing the JSON Pointer and rule for any failure. A schema inferred from examples describes only what the sample shows: objects stay open to extra keys, and value ranges, patterns and lengths are not guessed. Numbers beyond JavaScript precision keep the correct type but are left out of examples. Everything runs in your browser, and the validator is loaded only when you ask for it.

Frequently asked questions
Which JSON Schema version does the generator produce?
Draft 2020-12. Every schema starts with "$schema": "https://json-schema.org/draft/2020-12/schema" and is compiled in Ajv's Draft 2020-12 strict mode when you select Validate sample.
How does it decide which fields are required?
For an array of records, a key is required only when every record has it; keys missing from some records stay optional and are listed in the inference notes. A single object cannot show which keys are optional, so every key it has is marked required and the tool warns you. You can also turn required-field inference off.
Will my sample always validate against the generated schema?
For standard JSON, yes: types, nullable fields, formats and enums are only emitted when every sampled value satisfies them, and Validate sample confirms it with Ajv and ajv-formats. Number tokens outside the JavaScript range, such as 1e400, become Infinity when parsed and are reported as errors instead.

CodingTool is officially live on