JSON Schema Generator

Infer a draft 2020-12 JSON Schema from a JSON sample.

About JSON Schema Generator

Generate a JSON Schema (draft 2020-12) from a JSON sample, with types, required properties, array items and date formats inferred as you type.

How to use

  1. Paste a JSON sample, or load a .json file (up to 5 MB). Any JSON value is accepted; an object or an array of objects gives the most useful schema.
  2. Choose which properties are required. "Keys in every object" requires a key only when every object in the same position has it; "all keys" requires every key that was seen.
  3. Tick "additionalProperties: false" to make every object reject keys that the sample does not have.
  4. The schema updates as you type. Copy it, or Download it as a .schema.json file.

What it does

JSON Schema
string "type": "string"
YYYY-MM-DD string also "format": "date"
date-time string with seconds and a zone, such as 2024-01-31T10:00:00Z also "format": "date-time"
integer "type": "integer"
other number "type": "number"
boolean "type": "boolean"
null "type": "null"
object "type": "object" with properties and required
array "type": "array" with items
  • All elements of an array are merged into one items schema, and the objects among them are merged key by key, so a list of records gives one record schema. An empty array gets no items.
  • When one position holds several types, type is a list: ["string", "null"] for a string that is sometimes null, ["integer", "string"] for a mixed array. Integers mixed with other numbers are number.
  • format is added only when every string in that position is a valid date or date-time, so 2024-02-30 is not labelled a date.
  • The schema declares the 2020-12 draft in $schema. In "keys in every object" mode the sample always validates against its own schema.
  • It does not infer enum, pattern, minimum, maxLength, $ref and $defs, tuples, titles or descriptions, and it detects no formats other than the two above. A schema made from one sample describes that sample, so review it before using it as a contract.

Example

{ "id": 1, "joined": "2024-01-31" }
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "id": {
      "type": "integer"
    },
    "joined": {
      "type": "string",
      "format": "date"
    }
  },
  "required": [
    "id",
    "joined"
  ]
}

Privacy

Inference runs in the page. A dropped file is read locally, no request is made, and nothing is stored.

Frequently asked questions

What is JSON Schema used for?
It describes the shape of JSON data: which properties exist, their types and which are required. Validators use it to check API requests, configuration files and form data, and editors use it for autocompletion.
How do I make a property nullable in JSON Schema?
List null as one of its types: "type": ["string", "null"]. The nullable keyword belongs to OpenAPI 3.0, not to JSON Schema, and standard validators ignore it.
What does additionalProperties: false do?
It makes an object invalid when it has a property that is not listed under properties or matched by patternProperties. Without it, JSON Schema allows extra properties.
How do I mark a property as required in JSON Schema?
Add its name to the required array of the object schema, next to properties. A property that is listed under properties but not in required may be left out, though when present it must still match its schema.