Skip to content
ToolPlankDEV
JSON Tools
100% In-Browser Execution

Updated:

JSON Schema Generator

Paste one JSON document or several samples and get a JSON Schema as you type. This json schema generator merges the samples, so fields that are missing from some of them come out optional instead of wrong. Nothing is uploaded.

Options:

JSON samples

Input
0 chars · 0 lines

JSON Schema

Ready
Processing in browser...
0 chars · 0 linesUpdates as you type

Summary and notes

Samples merged, properties found, formats detected and notes about the samples appear here.

Processed on your device. Your text is not sent to our servers.

More free tools you may need next.

Quick Guide

How to use JSON Schema Generator

Simple step-by-step instructions to get the exact output you need.

  1. 01

    Paste one or more JSON samples

    Paste a JSON document, or several of them one after another, as JSON Lines, or open a file. Each document is a sample. More samples give a better schema. Example loads three user records, and the sample buttons load an API response, mixed types and a config file.

  2. 02

    Choose the draft and how strict to be

    Pick the draft for $schema, from 2020-12 down to draft 04. Decide which properties count as required, whether extra properties are allowed, and whether to detect formats and enums. Mixed types can be written as a type list or as anyOf.

  3. 03

    Read the schema and the summary

    The schema updates as you type. The panel under it shows how many samples were merged, how many properties were found, how many are required and optional, which formats were detected and notes about empty arrays or fields with several types.

  4. 04

    Copy, download or validate

    Copy the schema or download schema.json, or choose YAML for an OpenAPI components section. The swap button opens the JSON Schema Validator with the schema loaded so you can test real data against it.

How to generate a JSON Schema from JSON

A JSON Schema describes the shape of JSON: which keys exist, what type each value has and which keys are required. To generate a JSON Schema from JSON, the tool reads your sample, records the type of every value and writes the matching keywords. An object becomes type object with properties, a list becomes type array with items, and text, numbers and booleans get their own types.

A schema made from one sample is only a first draft, because one sample cannot show which fields are optional. Paste several samples and the json schema generator merges them. The processing happens in your browser, as the Privacy Policy describes.

JSON
{"id":1,"email":"ana@example.com","tags":["a"]}
{"id":2,"email":"ben@example.com","phone":null}

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "id": { "type": "integer" },
    "email": { "type": "string", "format": "email" },
    "tags": { "type": "array", "items": { "type": "string" } },
    "phone": { "type": "null" }
  },
  "required": ["id", "email"]
}

Why some fields are not required

With the default setting, a property is required only when it appears in every object that was seen at that place. In the example above, id and email are in both samples and tags and phone are in one each, so only id and email are required. That is the main reason to paste more than one sample.

  • In every sample: required means present in all objects seen. This is the default and the safest.
  • Any sample: every property that appeared anywhere is required. Use it when your samples are all complete.
  • None: the required list is left out, so any object that has the right types passes.

A single sample makes every property look required, so the tool adds a reminder when you paste only one.

Arrays and mixed types

The items of all arrays at the same place are merged into one items schema. If some items have an extra key, that key is optional in the merged schema, and if one item is a number and another a string, the type becomes a list of both. An array that was empty in every sample has no items schema, and the notes name it so you can add a sample that has items.

When a value has more than one type, for example text in one sample and null in another, the default is a type list such as type: [string, null]. Choose anyOf to get one branch for each type, which some OpenAPI tools prefer. Whole numbers and decimals merge into number, and a field that is only ever whole numbers is integer.

By default every item in an array shares one schema. Switch Arrays to By position when the array is a tuple, such as a coordinate pair. Draft 2020-12 writes prefixItems, and older drafts write an items array with additionalItems set to false.

Formats and enums

Detect formats adds a format keyword when every value of a field matches one: date-time, date, time, uuid, email, ipv4, ipv6 or uri. A single value that does not match removes the format, so a field is never labeled wrongly. Only formats that exist in the chosen draft are used. uuid appears from 2019-09, and date and time from draft 07.

Enums list the values of a text field when there are few of them and they repeat. The rule needs at least three values, and the number of different values must be at most half of the number seen. Three samples with two roles do not become an enum, because that could be chance. When a field can also be null, null is added to the enum so valid data still passes.

yaml
{"role":"user"} {"role":"admin"} {"role":"user"} {"role":"admin"}

$schema: https://json-schema.org/draft/2020-12/schema
type: object
properties:
  role:
    type: string
    enum:
      - user
      - admin
required:
  - role

Choosing a draft

The draft sets the $schema value and the keywords that are used. Draft 2020-12 is the current one and the right choice for new work. 2019-09 and draft 07 are still common in tools such as editors and API gateways. Draft 06 and draft 04 are for older systems, and draft 04 has no examples keyword, so examples are left out for it.

If you are writing an OpenAPI document, choose YAML under Output. The result can be pasted into components/schemas. OpenAPI 3.0 uses its own variant of JSON Schema, so check nullable and the type list against the version you target.

More options

  • Allow extra properties: turn it off to write additionalProperties: false on every object, so unknown keys fail validation.
  • Top-level array: treat a top-level array either as one array value or as a list of samples, so [{...},{...}] gives a schema for one item.
  • Add titles: writes a title from each property name, so first_name becomes First Name.
  • Add examples: keeps up to three example values from your samples for text and number fields.
  • Add observed limits: writes minLength, maxLength, minimum, maximum, minItems and maxItems from the values seen. Only use it when the samples cover the real range, because the limits come from the data you pasted.
  • Schema title: puts a title on the whole schema.

Limits and next steps

A schema inferred from samples describes the samples, not your intent. It cannot know that a number must be positive or that a field is a secret, so review it and add the rules that matter. The tool does not use $ref or $defs, and values nested deeper than 200 levels are left out with a note.

To test the schema against real data, open the JSON Schema Validator, which lists every error with its line and column. JSON to YAML converts a schema file you already have, Sort JSON Keys puts its keys in order, and JSONL Viewer helps you look through a large file of samples first.

Frequently Asked Questions

Technical Q&A for JSON Schema Generator

Common questions about edge cases, character encoding, and privacy guarantees.

Paste your JSON, preferably several samples, and read the schema next to it. Copy it or download schema.json.

Because they are missing from at least one sample. Required means present in every object that was seen, so more samples show which fields are really optional.

Choose 2020-12 for new work, and an older draft only if the tool that reads the schema needs it. Draft 07 and 2019-09 are common in editors and gateways.

Yes. Detect formats adds date-time, date, time, uuid, email, ipv4, ipv6 and uri when every value in a field matches that format.

Choose YAML as the output and paste it under components/schemas. Check nullable fields against the OpenAPI version you use, because 3.0 and 3.1 handle null differently.

Yes. Items of all arrays are merged, so keys that are missing from some items become optional. Set Top-level array to Each item is a sample to get a schema for one item.

A field that is null in some samples and text in others gets type [string, null], or an anyOf with both branches. A field that is always null gets type null.

Yes. Turn off Allow extra properties and every object gets additionalProperties: false.

Yes. Paste one document per line, or several documents one after another, and each one is merged as a sample.

No. The schema is made in your browser, so private payloads stay on your computer.