JSON Schema Generator

Infer a JSON Schema from sample data. Private, in your browser.

Input

Output

Ready
Ln 1, Col 1

Generate a JSON Schema from an example

Writing a schema by hand is slow. Paste a representative JSON sample and get a draft 2020-12 JSON Schema with types, required properties and string formats, ready to refine and use for validation, documentation or OpenAPI.

How to use it

  1. Paste a JSON sample into the Input panel. Arrays with several items give the best results.
  2. The schema appears in the Output panel.
  3. Copy it or download it as Root.schema.json, then add descriptions, enums or limits as needed.

What is inferred

  • type for every value, using integer or number as appropriate.
  • required: keys present in every object of an array.
  • Nullable values as ["string", "null"].
  • format for strings that are all emails, dates, date-times, URIs or UUIDs.

Validating data with the schema

Use any JSON Schema validator, for example Ajv in JavaScript:

import Ajv2020 from "ajv/dist/2020";
import addFormats from "ajv-formats";

const ajv = new Ajv2020();
addFormats(ajv);
const validate = ajv.compile(schema);
if (!validate(data)) console.log(validate.errors);

More JSON tools

All tools are free and run privately in your browser.

JSON Schema Generator FAQ

Which JSON Schema version is generated?

Draft 2020-12, the current version, declared with the $schema keyword. It also works with most draft-07 validators.

How are required properties decided?

A key is required if it appears in every object of the sample. Keys that are missing from some items are left optional.

Is my data uploaded to a server?

No. The JSON Schema Generator runs entirely in your browser using JavaScript. Your data is never uploaded, logged or stored, and the tool keeps working offline after your first visit.