JSON Schema Generator

Generate a JSON Schema from one or several sample JSON documents — Draft 2020-12 or Draft-07.

Sample JSON

JSON Schema

Samples

Several documents: JSON Lines, values separated by blank lines or a --- line, or one array of samples.
Only in Several documents mode. Without it, a top-level array is one sample.

Schema

Changes $schema and the name of the definitions keyword.
Every key in the sample becomes required. Off: nothing is required.
Adds additionalProperties: false to every object.
date-time, date, time, email, uuid, ipv4, ipv6, uri or hostname, only when every value of the field matches.

Extras (off by default)

Identical object shapes used at least twice move to $defs (Draft-07: definitions) and are referenced with $ref.
Copies up to 3 distinct values per field into the schema (strings cut at 60 characters), so the schema contains your data.
Adds a title made from each property name.
String or integer fields seen at least 20 times with at most 5 distinct values, each seen at least twice, get an enum.

Loading the editors…

Check the samples against this schema

This runs every sample above through the schema above with the same Ajv library the JSON Schema Validator uses, in your browser. A schema generated from samples should accept all of them, so this is a self-check, and each error shows its place as a JSON Pointer such as /orders/0/total.

Generate a JSON Schema from One or Several Sample Documents

Generate a JSON Schema from JSON: paste one sample or several, and fields missing from any sample become optional. Paste JSON or open a file, choose Draft 2020-12 or Draft-07, and the schema appears next to your sample. It reads one document or many. With several samples it merges them, so the schema shows which fields are always there, which are optional and which change type from one sample to the next.

Already have a schema? Feed it into the Mock JSON Data Generator to produce fake test data that matches the shape you just generated.

How to Use It

  • Paste your JSON into the left editor, open a .json, .jsonl or .txt file with Open file, or drop a file on the editor. Sample loads an example.
  • Choose Samples. One document reads a single JSON value. Several documents reads many samples at once and merges them.
  • Choose options: draft, required fields, additional properties, string formats, and the extras (reusable definitions, examples, titles, enums).
  • Click Generate, then copy or download the schema as schema.json, or use Check samples against schema to test it.

How the Schema Is Inferred

The generator reads every value it is given and records what it saw at each place: which types occurred, which keys were present in how many objects, what the items of each array looked like, and which strings could still be dates, e-mail addresses or other formats. It then writes the schema from those records. Because it works from everything it saw and not from the first value, the same properties, required list and types come out whatever the order of your samples. Only the order inside a type list or an anyOf follows the order in which kinds were first seen.

A value becomes string, boolean, null, object or array. A number is integer when its value is whole (5, 5.0 and 1E5 all count) and number otherwise. Objects become properties. Every array becomes "type": "array" with one items schema that merges all of its elements, in every sample. An empty array gives "items": {}, because nothing is known about its items. The output uses only type, properties, required, items, anyOf, additionalProperties, format, enum, examples, title and the definitions keyword. It does not guess minimums, maximums, lengths or patterns.

Numbers keep their spelling. A value such as 12345678901234567890 or 2.50 is read exactly as typed, so it appears unchanged if you add examples or enums, and a long integer is still typed as an integer.

Several Documents: Input Formats

Set Samples to Several documents when you have more than one example. Three layouts are accepted. JSON Lines has one JSON value per line. Values one after another can be separated by spaces, blank lines, or a line that contains only ---. And one top-level array can be read as separate samples when you tick Treat top-level array items as separate samples; without the box, an array is a single sample. A file ending in .jsonl or .ndjson switches the page to Several documents when you open it.

A syntax error names the document, the line and the column. For example, a trailing comma on the third line of a JSON Lines file, {"id": 3,}, gives: Document 3, line 3, column 10: Expected a property name in double quotes but found '}'.

Required or Optional? A Two-Sample Example

Properties are merged across samples: the schema describes the union of all keys. A key goes into required only if it is present in every sample. In the example below, both people have id and name, but only Ada has a phone, so phone is described but not required.

Two samples (JSON Lines)

{"id": 1, "name": "Ada", "phone": "555-0101"}
{"id": 2, "name": "Grace"}

Schema (Several documents, defaults)

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

Mark all properties as required changes this. In One document mode, every key of the sample becomes required (inside an array of objects, only the keys that every item has). In Several documents mode it requires every key seen in any sample, so a sample that lacks one of those keys would fail the schema. Leave it off when your samples vary. The page switches it off for you when you choose Several documents, unless you have changed the box yourself. With the box off, Several documents mode requires the keys present in every sample, and One document mode writes no required list at all.

Nullable and Mixed Types

When a field is one type in some samples and null in others, the generator writes a type array such as "type": ["string", "null"]. That form is valid in both Draft-07 and Draft 2020-12, so no OpenAPI-style nullable keyword is written. A field that is missing from some samples is optional, not nullable: in the example, middleName is null once and missing once, so it is not required and may be a string or null.

Three samples

{"id": 1, "middleName": "Marie"}
{"id": 2, "middleName": null}
{"id": 3}

Schema: middleName is optional and nullable

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Generated schema",
  "type": "object",
  "properties": {
    "id": {
      "type": "integer"
    },
    "middleName": {
      "type": [
        "string",
        "null"
      ]
    }
  },
  "required": [
    "id"
  ]
}

Several primitive types give a type array in the order they were first seen, so null comes first if the first sample has a null. An integer together with a decimal number becomes number, since every integer is also a number. When a field mixes objects or arrays with other types, the generator writes anyOf with one branch per kind. Samples of the same kind are merged into one branch, so two objects with different keys become a single object branch with the union of their keys.

Four samples with different kinds of value

{"value": 42}
{"value": "42"}
{"value": {"unit": "kg", "amount": 42}}
{"value": null}

Schema: one anyOf branch per kind

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Generated schema",
  "type": "object",
  "properties": {
    "value": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "string"
        },
        {
          "type": "object",
          "properties": {
            "unit": {
              "type": "string"
            },
            "amount": {
              "type": "integer"
            }
          },
          "required": [
            "unit",
            "amount"
          ]
        },
        {
          "type": "null"
        }
      ]
    }
  },
  "required": [
    "value"
  ]
}

Draft-07 and Draft 2020-12: What Differs Here

  • Dialect URI. The $schema line names the draft you picked.
  • Definitions. Draft 2020-12 stores reusable pieces under $defs and points to them with #/$defs/Name. Draft-07 uses definitions and #/definitions/Name.
  • Siblings of $ref. In Draft-07 any keyword next to a $ref is ignored, so with Add titles the generator does not put a title beside a reference in Draft-07. Draft 2020-12 allows it.
  • Tuple arrays. Draft 2020-12 describes arrays with fixed positions using prefixItems, while Draft-07 uses items as an array. The generator does not write tuple arrays. It treats every array as a list whose items share one merged schema, so [1, "a"] gives items of type integer or string. If your arrays are positional, edit that part by hand.

Everything else the tool writes (types, properties, required, items, anyOf, enum, format) is the same in both drafts.

When to Extract Repeated Object Shapes

Extract repeated object shapes is off by default. Turn it on when the same object appears in more than one place, such as a billing and a shipping address, or the items of two lists. Objects with identical structure (the same properties, the same schemas and the same required list; property order does not matter) that occur at least twice are moved into the definitions keyword and replaced with a $ref. Shapes that are merely similar stay where they are. Each definition is named in PascalCase after the first property it was found under (billing becomes Billing), and a second shape with the same name gets a number: Billing2.

One document, Extract repeated object shapes on

{"billing": {"street": "1 Main St", "city": "Oslo"}, "shipping": {"street": "9 Side Rd", "city": "Bergen"}, "note": "gift"}

Schema (Draft 2020-12)

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Generated schema",
  "type": "object",
  "properties": {
    "billing": {
      "$ref": "#/$defs/Billing"
    },
    "shipping": {
      "$ref": "#/$defs/Billing"
    },
    "note": {
      "type": "string"
    }
  },
  "required": [
    "billing",
    "shipping",
    "note"
  ],
  "$defs": {
    "Billing": {
      "type": "object",
      "properties": {
        "street": {
          "type": "string"
        },
        "city": {
          "type": "string"
        }
      },
      "required": [
        "street",
        "city"
      ]
    }
  }
}

The result is shorter and has one place to edit. The name comes from the first use, so two unrelated objects that happen to have identical fields will share one definition; rename it if the name is misleading.

String Formats and Their Limits

With Detect string formats on, the generator can write nine formats: date-time (such as 2026-01-15T10:30:00Z, with a real calendar date), date, time (with a zone, such as 10:30:00Z), email, uuid, ipv4, ipv6, uri (an absolute address with ://) and hostname (ASCII, at least two labels). The rule is strict: a format is written only if every string seen at that place, across all array items and all samples, matches. One value that does not match, such as an empty string or n/a, means no format at all. A nullable field keeps its format, for example {"type": ["string", "null"], "format": "date"}. A value that fits two formats gets the first of this list: date-time, date, time, email, uuid, ipv4, ipv6, uri, hostname.

The checks are deliberately simple and are not full RFC parsers. They do not accept internationalised addresses or host names, quoted e-mail names or mailto: links. Also, many validators treat format as a hint unless format checking is switched on, so do not rely on it to reject bad data unless you have configured your validator to assert formats.

Examples, Titles and Enums: What Can and Cannot Be Inferred

Add examples copies up to three distinct values per field, in the order they were first seen, into examples. Strings longer than 60 characters are cut at 60. Because examples copy your values into the schema, check the output before sharing it if the samples contain personal or confidential data. Add titles turns property names into readable titles (firstName becomes First name, home_address becomes Home address). Infer enums writes an enum only for string or integer fields that were observed at least 20 times with at most 5 distinct values, each seen at least twice.

An inferred enum is a guess. Twenty rows containing new, open and closed say nothing about a value that has not appeared yet, such as blocked. Remove the enum when new values may be added later. The same goes for formats and types: the tool can only report what it saw.

Open a File, Large Inputs and Limits

Open file accepts .json, .jsonl, .ndjson and .txt, and you can also drop a file onto the left editor. The page shows the file name and size. Reading and generating happen in a background worker, so a large file does not freeze the page, and a Cancel button appears if it takes longer than a second. A file over 1.5 MB is not shown in the editor (the box says "Large file loaded") and the schema is generated straight from the file. Files up to 50 MB are accepted; above that the page asks you to split the file. Objects and arrays may be nested up to 500 levels. Text pasted into the box is limited to 20 million characters, and for anything over a few megabytes Open file is the better route.

Checking Samples Against the Schema

Check samples against schema runs your samples through the generated schema. On success it says the samples are valid. On failure it lists the first 20 errors, each with the JSON Pointer of the failing place. In Several documents mode every sample is checked and the failing document numbers are listed. If you left Mark all properties as required on in that mode, samples that lack a key will fail, which is exactly what that option asks for. Open in JSON Schema Validator sends the sample and schema to the JSON Schema validator page for a closer look (One document mode).

A Schema Inferred from Samples Describes the Samples

The tool can only describe the data you give it, not your intent. Review the result before you use it. A field that is always an integer in your samples may later hold decimals, a field that is always present may be optional in the real API, and a field that was never null may become null. Use more samples, including the awkward ones (empty arrays, nulls, missing optional fields), and add the constraints that samples cannot show, such as minimum, maxLength and pattern, by hand. A good flow is to generate, review, check real documents with the validator, and then build on the schema with the code generator or the mock data generator.

JSON Schema Generator: Options Explained

JSON Schema has several dialects and configuration choices that change the generated output. Here is what each option on this page controls.

Draft 2020-12 vs Draft-07

Draft 2020-12 is the current JSON Schema specification version; Draft-07 is still widely supported by older validators and tools such as some IDEs and OpenAPI 3.0 tooling. Pick whichever your validator or framework expects.

One Document or Several Documents

One document describes a single sample. Several documents merges many samples: properties are the union of all keys, and a key is required only when every sample has it.

Mark All Properties as Required

In One document mode every key of the sample becomes part of required. In Several documents mode every key seen in any sample becomes required. Turn it off if your samples are only partial examples and some fields may legitimately be absent.

Disallow Additional Properties

Sets additionalProperties: false on every object in the schema, so validation fails if the real data contains extra keys not seen in your samples. Useful for strict API contract testing.

String Format Detection

Adds a format keyword (date-time, date, time, email, uuid, ipv4, ipv6, uri or hostname) only when every string at that place matches, giving validators extra context beyond a plain type: "string".

Extract Repeated Object Shapes

Moves object shapes that occur at least twice into $defs (or definitions in Draft-07) and refers to them with $ref, which keeps large schemas short and consistent.

Examples, Titles and Enums

Optional extras, all off by default. Examples copy up to three of your values per field, titles come from property names, and enums are only inferred for fields seen at least 20 times with at most 5 distinct values.

Who Uses This Tool?

API Developers

Generate a schema from example responses to validate request and response bodies in an OpenAPI spec, Express middleware, or FastAPI/Pydantic model.

QA & Contract Testing

Turn captured API responses into a schema, then validate future responses against it to catch breaking changes automatically in CI.

Data Engineers

Generate a schema for JSON documents or JSON Lines exports stored in a document database or data lake to document the expected shape of the data.

Tooling & Config Authors

Produce a starter schema for a JSON configuration file so editors like VS Code can offer autocomplete and validation via $schema.

Frequently Asked Questions

What is a JSON Schema?

A JSON Schema is itself a JSON document that describes the structure, types, and constraints of other JSON data — which fields exist, their types, which are required, and more. It's used for validation, documentation, and code generation.

Which draft version should I choose?

Use Draft 2020-12 for new projects — it's the current specification. Use Draft-07 if your validation library, IDE, or framework (some OpenAPI 3.0 tooling, for example) doesn't yet support the newer draft.

How does it handle arrays with objects that have different fields?

The tool merges the shape of every object in the array. A field present in every item stays in required (if that option is enabled); a field present in only some items is dropped from required but still described in properties.

Can the generated schema validate my JSON later?

Yes. The output is a standard JSON Schema document you can use with any compliant validator (Ajv, jsonschema in Python, etc.) or reference via the $schema keyword in editors that support JSON Schema-based autocomplete.

Is my JSON data uploaded anywhere?

No. All schema generation happens locally in your browser with JavaScript. Nothing is sent to a server.

Can I generate typed code instead of a schema?

Yes — use the JSON to TypeScript, Python & Go Code Generator to produce a TypeScript interface, Python dataclass, or Go struct from the same kind of sample payload.

Can I generate fake test data from a schema?

Yes — paste the schema this tool generates into the Mock JSON Data Generator to produce realistic fake rows (names, emails, IDs, and more) matching that exact structure.

Can I generate a schema from several JSON samples?

Yes. Set Samples to Several documents and paste JSON Lines, several JSON values separated by blank lines or a --- line, or one array with “Treat top-level array items as separate samples” ticked. Properties are merged across all samples, and a key is required only if every sample has it. If “Mark all properties as required” is on, every key seen in any sample is required instead.

How are null values handled?

A field that is null in some samples and one other type in the rest becomes a type array such as "type": ["string", "null"] (null is listed where it was first seen), in both Draft-07 and Draft 2020-12. A field missing from some samples is optional, not nullable. A field that is only ever null gets "type": "null", and null mixed with objects or arrays becomes one anyOf branch.

Related Tools

Built by Deepak Kumar — a developer who wanted a JSON tool that respects your privacy. All processing happens in your browser. Your data never leaves your device.