JSON Schema Generator

Infer a JSON Schema from example data in one paste.

Runs in your browser Instant No sign-up
Draft
Indent
JSON sample
JSON Schema

Paste, type or drop a file — output appears as you type.

Waiting for input
Processed locally · nothing is uploadedProcessed locally

How it works

Paste example JSON and get a JSON Schema that describes it — ready for validators, editors and API docs:

  1. Objects become {"type": "object", "properties": {…}} with a required list of keys present in every sample.
  2. Arrays become {"type": "array", "items": …}. When the array holds several objects, they are merged, so the item schema covers every key that appears.
  3. Whole numbers become integer; if any value has a decimal part the type is number.
  4. Values that are sometimes null become a type list such as ["string", "null"].
  5. Mixed types become a type list (["string", "integer"]) or, when objects and arrays are involved, an anyOf.
  6. Nested objects are inlined where they appear — no $defs or $ref to chase.

Example

{
  "id": 42,
  "owner": { "id": 7, "name": "Linh", "email": null },
  "tasks": [
    { "id": 1, "done": true, "estimate": 3.5 },
    { "id": 2, "done": false, "assignee": "Minh" }
  ]
}

produces (abridged to the tasks property):

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "tasks": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": { "type": "integer" },
          "done": { "type": "boolean" },
          "estimate": { "type": "number" },
          "assignee": { "type": "string" }
        },
        "required": ["id", "done"]
      }
    }
  },
  "required": ["id", "owner", "tasks"]
}

estimate and assignee are not required because each appears in only one task.

When to use it

Generating a schema from a sample is a quick way to start an API contract, validate webhook payloads, get autocomplete and validation for a JSON config file in your editor (VS Code reads a $schema URL or the json.schemas setting), or document the shape of data you received from another team.

Paste several representative records as an array rather than a single object: required fields, optional fields and nullable types are inferred from what varies between the samples. If the sample doesn’t parse, the error panel shows the exact line and column and offers Fix with JSON Repair.

Options

  • Draft — 2020-12 or draft-07 (sets the $schema URL).
  • Mark required — emit required arrays based on key presence.
  • No extra properties — add additionalProperties: false to every object.
  • Indent — 2 spaces, 4 spaces or tabs.

Validating data with the schema

import Ajv2020 from 'ajv/dist/2020';

const ajv = new Ajv2020({ allErrors: true });
const validate = ajv.compile(schema);
if (!validate(data)) console.error(validate.errors);

For draft-07 schemas, use the default import Ajv from 'ajv'. In Python, jsonschema.validate(instance, schema) works with both drafts.

Refining the schema

A schema inferred from examples describes the sample, not your intent. Before publishing it:

  • Add format (email, date-time, uri), enum, minimum/maximum and pattern where you know the rules.
  • Add title and description so the schema documents itself in editors and API docs.
  • Revisit required if your sample was a single object — every key in it is marked required.

Prefer code over a schema file? Generate Zod schemas, TypeScript types, Go structs or Pydantic models from the same sample.

Frequently asked questions

Which JSON Schema draft should I pick?

Use 2020-12, the current version, unless a tool requires something older. Many validators and platforms (older Ajv setups, some IDE plugins, OpenAPI 3.0-era tooling) still expect draft-07; the generated keywords are the same, only the `$schema` URL changes.

How is "required" decided?

A property is required when it appears in every sample object. If you paste an array of objects, keys missing from some items are left out of `required`. Turn off "Mark required" to make every property optional.

What does "No extra properties" do?

It adds `"additionalProperties": false` to every object, so validation fails when data contains keys that weren't in your sample. Useful for strict contracts and config files, but risky for third-party APIs that add fields over time.

Why is a property `{"type": "null"}`?

Every sample value was null, so the real type is unknown. Edit it to something like `{"type": ["string", "null"]}`, or give a sample where the field has a value.

Is my data uploaded?

No. The schema is inferred entirely in your browser — nothing is uploaded.

Last updated