Skip to content
Devtoolry

JSON Schema Generator

Generate a JSON Schema from example JSON online. Arrays are merged into optional and nullable fields, and formats like date-time, email and uuid are detected.

Something not working, or missing a feature? Send feedback

About the JSON Schema Generator

The JSON Schema Generator writes a JSON Schema from an example document, so you do not have to type out every property by hand. Give it a real API response or config file and it describes each value's type, detects formats such as date-time, email, uri and uuid, and merges the items of arrays, making keys optional or nullable when only some items have them.

Conversion happens in your browser, so your files and records stay private.

How to use the JSON Schema Generator

  1. Paste example JSON, or open a .json file. An array of several records gives a better schema than a single one.
  2. Choose the draft: 2020-12 for current validators, Draft 7 for older tools and OpenAPI 3.0-era projects.
  3. Decide whether keys present everywhere are required, whether extra keys are rejected and whether string formats are detected.
  4. Copy or download schema.json, then tighten it by hand with enums, ranges and patterns that one example cannot show.

Examples

Optional and nullable fields from an array of records

Input

[
  { "id": 1, "email": "[email protected]", "plan": "pro", "trialEnds": null },
  { "id": 2, "email": "[email protected]", "plan": "free", "trialEnds": "2026-11-01T00:00:00Z", "referrer": "blog" }
]

Result

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

referrer is optional because only one record has it, and trialEnds allows null because one record has null.

A strict config schema (draft 7)

Input

{ "name": "devtoolry", "port": 8080, "debug": false }

Result

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Config",
  "type": "object",
  "properties": {
    "name": {
      "type": "string"
    },
    "port": {
      "type": "integer"
    },
    "debug": {
      "type": "boolean"
    }
  },
  "required": [
    "name",
    "port",
    "debug"
  ],
  "additionalProperties": false
}

No extra keys adds additionalProperties: false, so a misspelt key in the config fails validation.

Common mistakes

  • Generating from a single record. With one example, every key looks required and every value has exactly one type. Paste an array of several real records so optional and nullable fields show up.
  • Shipping the draft unchanged. An example cannot show limits or allowed values. Add enum, minimum, maxLength or pattern where the API documents them before using the schema for validation.

Works well with the JSON Schema Generator

Frequently asked questions

How does it decide which keys are required?

A key is required when it appears in every object seen at that position. With an array of records, a key that is missing from even one record becomes optional. Turn off Mark keys required to make everything optional.

Why is a field typed ["string", "null"]?

Because the example contains both a string and null for it. A union type in a type array is the standard way to describe a nullable value in JSON Schema; in OpenAPI 3.0 you would write nullable: true instead.

Can a schema from one example be trusted?

It describes the example, not every valid document. Numbers that happen to be whole become integer, a value that is always "pro" or "free" stays a plain string, and an empty array accepts any items. Review the schema and add minimum, maximum, enum, pattern and minItems rules where you know them.