JSON Schema Generator

Runs locally in your browser

Infer a Draft 2020-12 JSON Schema from sample JSON

JSON sample

Paste a JSON sample or load an example to generate a schema.
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 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.
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.

CodingTool is officially live on

Launched on StartupBaseCodingTool.dev - Free, Fast & Easy Developer Tools in One Place | Product HuntCodingTool - Featured on Startup FameFazier badgeListed on Turbo0Featured on Twelve ToolsFeatured on Findly.tools