consolelog.tools

JSON Schema Generator

Paste a JSON sample and get a smart JSON Schema — not a naive one. It merges every element of an array so that required only lists keys present in every record, widens a field's type when it varies, adds null to the type wherever a value can be null, and turns a repeated small string set into an enum. It detects string formats (email, uri, uuid, date-time, date, ipv4), emits Draft 2020-12 or Draft-07, and ships a live validator that pastes a payload and shows exactly which instance paths would fail.

About this ToolHow it works, benefits & use cases

Paste a JSON sample and get a smart JSON Schema, not a naive one-to-one translation. The generator merges every element of an array to work out which keys are genuinely required (present in every record) versus optional (missing from some), which values are nullable (so "null" is added to their type), and which string fields are really enums (a small, repeating set of values). It detects string formats — email, uri, uuid, date-time, ISO date and ipv4 — emits Draft 2020-12 or Draft-07, and can include $id, title, description, an examples array, and inferred numeric minimum/maximum. A built-in validator lets you paste a second payload and instantly see which instance paths would fail, so the tool both generates and checks. The whole configuration lives in a shareable URL.

How to Use

  1. 1Paste a JSON object — or better, an array of records — into the input (or load an example).
  2. 2Pick the draft version (Draft 2020-12 or Draft-07) and set a title and optional $id / description.
  3. 3Toggle inference: string-format detection, enum detection, additionalProperties, and numeric range inference.
  4. 4Read the generated JSON Schema; switch the output toggle to see an inferred example payload that conforms to it.
  5. 5Paste another JSON value into "Validate a payload" to see exactly which instance paths pass or fail, then copy or share.

Key Benefits

  • Array-sample merging keeps required limited to keys present in every element
  • Nullable values add "null" to the type instead of being dropped or marked required
  • Enum detection turns a repeated small string set into an enum constraint
  • String-format detection: email, uri, uuid, date-time, date and ipv4
  • Draft 2020-12 or Draft-07 output with optional $id, title, description and examples
  • Optional inferred numeric minimum / maximum from the observed values
  • A live validator reports the exact failing instance paths for any payload
  • Shareable URL captures the JSON, draft, options and output mode

Common Use Cases

  • Turning a sample API response into a JSON Schema for request/response validation
  • Documenting an existing payload shape with a precise, draft-correct schema
  • Inferring which properties are required or nullable from a list of real records
  • Deriving an enum constraint from a status or role field that only takes a few values
  • Confirming a draft schema accepts the payloads you expect and rejects the ones you do not

JSON Schema (2020-12)

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Product",
  "type": "array",
  "items": {
    "type": "object",
    "properties": {
      "sku": {
        "type": "string"
      },
      "price": {
        "type": "number"
      },
      "status": {
        "type": "string",
        "enum": [
          "active",
          "archived"
        ]
      },
      "tags": {
        "type": "array",
        "items": {
          "type": "string"
        }
      },
      "featured": {
        "type": "boolean"
      }
    },
    "required": [
      "sku",
      "price",
      "status"
    ],
    "additionalProperties": false
  }
}
Schema validates the source sample
5fields3required2optional0nullable1enums0formats

Validate a payload

JSON sample

Tip: paste an array of records — the more samples, the smarter the required / nullable / enum inference.

Draft & inference

email, uri, uuid, date-time…

repeated small string sets

reject unknown keys

from observed numbers

add an examples array

Why an array sample is worth more

From a single object the tool can only guess every field is required and non-null. Paste an array and it merges all elements: a key missing from any element drops out of required, a value seen as null anywhere adds "null" to its type, mixed types widen to a type array or anyOf, and a string field with a small repeating set of values becomes an enum.

It validates, not just generates

The “Validate a payload” box runs the inferred schema against any JSON you paste and lists the exact failing instance paths — missing required properties, wrong types, out-of-enum values, bad formats, or disallowed extra keys.

Was this tool helpful?

Share Your Experience

Help others discover this tool!

Related tools