Skip to content
UniKit

JSON Schema generator

Infer a draft-07 JSON Schema from a JSON sample: types, required fields, date-time / email / uri / ipv4 formats, enums for low-cardinality fields, array items and nested objects, with optional additionalProperties: false, $defs reuse and YAML output.

Runs in your browserEvery computation happens in your browser — your data never leaves this device.

Sample JSON and options

Output format
Inference options
additionalProperties: falseOnly allow the keys seen in the sample
Detect formats (date-time / email / uri / ipv4)
Extract repeated structures into $defs

Generated schema

The output is draft-07; $defs is the 2019-09 spelling, and draft-07 calls the same keyword definitions.

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "id": {
      "type": "integer"
    },
    "name": {
      "type": "string"
    },
    "email": {
      "type": "string",
      "format": "email"
    },
    "homepage": {
      "type": "string",
      "format": "uri"
    },
    "createdAt": {
      "type": "string",
      "format": "date-time"
    },
    "ipv4": {
      "type": "string",
      "format": "ipv4"
    },
    "active": {
      "type": "boolean"
    },
    "score": {
      "type": "number"
    },
    "tags": {
      "type": "array",
      "items": {
        "type": "string",
        "enum": [
          "math",
          "engine"
        ]
      }
    },
    "address": {
      "type": "object",
      "properties": {
        "city": {
          "type": "string"
        },
        "zip": {
          "type": "string"
        }
      },
      "required": [
        "city",
        "zip"
      ]
    },
    "orders": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "sku": {
            "type": "string",
            "enum": [
              "A-1",
              "B-2"
            ]
          },
          "qty": {
            "type": "integer",
            "enum": [
              2,
              1
            ]
          },
          "address": {
            "type": "object",
            "properties": {
              "city": {
                "type": "string",
                "enum": [
                  "London",
                  "Paris"
                ]
              },
              "zip": {
                "type": "string",
                "enum": [
                  "SW1A",
                  "75001"
                ]
              }
            },
            "required": [
              "city",
              "zip"
            ]
          }
        },
        "required": [
          "sku",
          "qty",
          "address"
        ]
      }
    }
  },
  "required": [
    "id",
    "name",
    "email",
    "homepage",
    "createdAt",
    "ipv4",
    "active",
    "score",
    "tags",
    "address",
    "orders"
  ]
}

Statistics

Properties18
Objects4
Arrays2
Enums5
Formats4
$defs entries0
Max depth3

What this tool does

  • Agree on a contract before wiring an API: paste the real response and get a draft-07 schema with types, required fields and formats instead of writing it by hand.
  • Validate a config file: turn a sample config into a schema and check user input with any JSON Schema validator, so typos and wrong types fail fast.
  • Feed a form or low-code builder: fields with few distinct values get an enum you can reuse as dropdown options.
  • Fill in components.schemas for an OpenAPI document by inferring the shape from a sample object first.

Example

Input

{
  "id": 1024,
  "name": "Ada Lovelace",
  "email": "ada@example.com",
  "createdAt": "2024-05-06T07:08:09Z",
  "tags": ["math", "engine"],
  "address": { "city": "London", "zip": "SW1A" },
  "billing": { "city": "London", "zip": "SW1A" }
}

Output

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "id": {
      "type": "integer"
    },
    "name": {
      "type": "string"
    },
    "email": {
      "type": "string",
      "format": "email"
    },
    "createdAt": {
      "type": "string",
      "format": "date-time"
    },
    "tags": {
      "type": "array",
      "items": {
        "type": "string",
        "enum": [
          "math",
          "engine"
        ]
      }
    },
    "address": {
      "$ref": "#/$defs/Address"
    },
    "billing": {
      "$ref": "#/$defs/Address"
    }
  },
  "required": [
    "id",
    "name",
    "email",
    "createdAt",
    "tags",
    "address",
    "billing"
  ],
  "$defs": {
    "Address": {
      "type": "object",
      "properties": {
        "city": {
          "type": "string"
        },
        "zip": {
          "type": "string"
        }
      },
      "required": [
        "city",
        "zip"
      ]
    }
  }
}

address and billing are structurally identical, so they become $defs.Address behind a $ref; tags only has two values, which is why an enum appears.

Frequently asked questions

Why is every field marked as required?

Every key present in a single sample counts as required, because inference only sees that one document. To get a better answer, wrap the objects in an array: only keys present in every sample end up in required.

When does an enum get generated?

Only when a position has several samples and the distinct values stay under the limit (six by default, set it to 0 to disable). A lone example object has nothing to compare against, so no enum appears.

Can format detection misfire?

A format is written only when every string at that position matches it, for example all values must look like emails to get email. Lookalikes such as the version 1.2.3 do not match date-time and fall back to plain string; you can switch format detection off entirely.

What is the difference between $defs and definitions?

Objects that appear twice or more with an identical structure are pulled into $defs and referenced by $ref. $defs is the name introduced in JSON Schema 2019-09 while draft-07 calls the same keyword definitions — the contents are identical, so rename the key to match your validator.

Can I use the result in OpenAPI?

Yes. OpenAPI 3.1 uses JSON Schema directly, so paste the properties block into components.schemas. For OpenAPI 3.0 drop the $schema line and adjust keywords such as nullable.

Keywords:json schemaschema generatordraft-07json 校验json schema 生成类型推断infer schemaapi contract数据校验openapi schema

Related tools