JSON Schema Generator.

Generate a JSON Schema from any JSON sample — pick the draft (2020-12, 2019-09, or draft-07), control required keys, and add examples or an $id. Instant and 100% private, in your browser.

No signup · No uploads · No file-size cap

JSON Schema

Generate JSON Schema online - free and private

A JSON Schema generator creates a validation schema from sample JSON. Paste a realistic object or array above and generate a schema with inferred types, nested properties, array items, required fields, examples, and an optional $id.

Choose the schema draft your validator needs

Different projects use different JSON Schema drafts. This tool supports draft-07, 2019-09, and 2020-12, so you can generate JSON Schema that matches your validator, API docs, or config workflow.

What a generated schema looks like

From this sample:

{ "id": 1, "name": "Ada", "email": "ada@example.com", "active": true }

you get a validation contract:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "id":     { "type": "integer" },
    "name":   { "type": "string" },
    "email":  { "type": "string" },
    "active": { "type": "boolean" }
  },
  "required": ["id", "name", "email", "active"]
}

Now { "id": "1" } fails validation — the ID is a string, not an integer. That is the whole point: catching bad data at the boundary, before it reaches your code.

Schema vs TypeScript — why you want both

These solve different problems and people routinely pick the wrong one.

A TypeScript interface checks your code at compile time and then vanishes. It is erased before your program ever runs, so it cannot inspect what an API actually sent you. Writing const user: User = await res.json() is a promise to the compiler, not a check — if the server returns null, your code crashes exactly as it would have without types.

A JSON Schema is data, so it still exists at runtime. You validate the response against it before you trust a single field.

The right setup is both, generated from the same sample: the interface for autocomplete and compile-time safety inside your code, the schema for guarding the network boundary.

Validating against your schema

JavaScript (Ajv) — the standard choice:

import Ajv from "ajv";

const ajv = new Ajv();
const validate = ajv.compile(schema);

if (!validate(data)) {
  console.error(validate.errors);   // exactly which field failed, and why
}

Python (jsonschema):

from jsonschema import validate, ValidationError

try:
    validate(instance=data, schema=schema)
except ValidationError as e:
    print(e.message, "at", list(e.path))

Get the required list right

The generator marks every key in your sample as required, which is almost always too strict for a real API. If your one sample record happened to include middleName, the schema will now reject every user who does not have one.

Two fixes. Paste an array of several varied records — one with nulls, one missing optional fields, one fully populated — so genuinely optional keys can be detected. Then review the required list by hand and remove anything that is not truly mandatory. This is the single most common mistake when generating schemas, and it produces a contract that rejects perfectly valid data.

Why use this JSON Schema generator?

It gives you a strong first draft without uploading data. After generation, review required keys and null handling, then use the schema for validation or documentation. Need TypeScript too? Try JSON to TypeScript or read how to generate JSON Schema.

FAQ

JSON Schema, answered.

How do I generate JSON Schema from JSON? +

Paste a representative JSON sample into the JSON Schema Generator, choose your schema draft and required-field options, then generate. The tool infers object properties, arrays, strings, numbers, booleans, nulls, and nested data.

Which JSON Schema drafts are supported? +

The generator supports modern JSON Schema drafts including 2020-12, 2019-09, and draft-07. Choose the draft your validator or API tooling supports.

Can the generator mark required fields? +

Yes. You can control required-field behavior. For strict schemas, mark keys as required. For sample arrays, optional fields can be detected when a key appears in some objects but not others.

Does it infer integer, number, boolean, null, and array types? +

Yes. The tool distinguishes integers from numbers, detects booleans and nulls, creates item schemas for arrays, and builds nested object properties from your JSON sample.

Can I add examples and an $id to the schema? +

Yes. The generator can include examples and an $id so the output is more useful for validators, documentation, API contracts, and schema registries.

Is my JSON sample private? +

Yes. JSON Schema generation runs entirely in your browser. Your sample data is never uploaded or stored, which is important for private API payloads and internal config files.

Which JSON Schema draft should I choose? +

2020-12 is the current standard and the right default for new projects. Choose 2019-09 or draft-07 only if your validator requires it — draft-07 in particular is still what many older libraries and tools support, so check what your validator understands before you commit to the newest draft.

What is the difference between a JSON Schema and a TypeScript interface? +

A JSON Schema validates data at runtime; a TypeScript interface only checks your code at compile time and disappears entirely when the program runs. So a TypeScript type cannot stop a misbehaving API from crashing you, but a schema can — you validate the response against it before you trust it. Most teams generate both from the same sample and use each for its own job.

How do I decide which fields are required? +

The generator marks every key present in your sample as required by default, which is usually too strict for a real API. Review the list and remove anything genuinely optional. If you paste an array of several varied records, fields missing from some of them can be detected as optional automatically.

How do I validate JSON against the generated schema? +

Use a validator library for your language — Ajv in JavaScript, jsonschema or fastjsonschema in Python, or everit in Java. Load the schema, load the data, and validate before your code touches the values. This is what protects you at the network boundary, which is exactly where types alone cannot help.