Data ToolsA little help for every day

Search by name or task, such as JSON or percentage.

Data Tools

JSON Schema Generator from Sample JSON

Generate a JSON Schema from example JSON: infers types, required keys, integer vs number and formats such as email and date-time, for Draft 2020-12 to Draft-04.

View all tools
ResultUpdates as you type
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "id": {
      "type": "integer"
    },
    "name": {
      "type": "string"
    },
    "email": {
      "type": "string",
      "format": "email"
    },
    "active": {
      "type": "boolean"
    },
    "score": {
      "type": "number"
    },
    "createdAt": {
      "type": "string",
      "format": "date-time"
    },
    "tags": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "address": {
      "type": "object",
      "properties": {
        "city": {
          "type": "string"
        },
        "postcode": {
          "type": "null"
        }
      },
      "required": [
        "city",
        "postcode"
      ]
    },
    "orders": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "total": {
            "type": "number"
          },
          "coupon": {
            "type": "string"
          }
        },
        "required": [
          "id",
          "total"
        ]
      }
    }
  },
  "required": [
    "id",
    "name",
    "email",
    "active",
    "score",
    "createdAt",
    "tags",
    "address",
    "orders"
  ]
}

Inferred 14 properties (including nested ones) from 1 sample. The schema only reflects the sample, so add constraints such as enum or minimum as needed.

How to use JSON Schema Generator from Sample JSON

Paste one JSON document, or several samples one per line, and the schema updates as you type. Choose the draft, decide how strict it should be with the tick boxes, then press Copy result.

  1. Paste sample JSONPaste a typical document into Sample JSON, or several compact samples one per line to merge them.
  2. Choose draft and optionsPick Draft 2020-12, 2019-09, Draft-07 or Draft-04 and tick required keys, integers, formats or no extra keys.
  3. Review and copy the schemaCheck the property count in the note, add enum or minimum rules by hand if needed, and press Copy result.

How types are inferred: a worked example

In the sample record, id: 1024 becomes "type": "integer", score: 98.5 becomes number, the email address gets "format": "email", createdAt gets "format": "date-time" and the null postcode becomes type null. The orders array holds two objects, {"id":"A-1","total":25} and {"id":"A-2","total":12.4,"coupon":"SPRING"}. Their schemas are merged into one items schema: total is a whole number in one item and a decimal in the other, so it becomes number, and coupon appears in only one item, so it is left out of required. Besides email and date-time, strings are checked for date, uuid, ipv4 and uri formats.

Several samples, required keys and strictness

Put one compact JSON document on each line to infer from several samples at once. A key is listed in required only if every sample has it, and a field that changes type between samples gets a type array such as ["string", "null"]. Empty arrays produce just "type": "array" with no items schema. Ticking Disallow extra keys adds "additionalProperties": false to every object, so validators reject unknown keys. The $schema line points at the draft you choose, which validators read to decide which rules apply. The schema only reflects your samples, so add enum, minimum, maxLength or pattern constraints yourself.

Accuracy and data handling

Keep the original data and spot-check fields, types and delimiters before using an important conversion. The calculation runs in your current browser; the tool code does not send the input to a processing API.

FAQ

What is a JSON Schema used for?

A JSON Schema describes the structure and types that JSON data must follow. It is used to validate API requests and responses, check configuration files, generate forms and documentation, and test data.

Which JSON Schema drafts are supported?

You can output Draft 2020-12, Draft 2019-09, Draft-07 or Draft-04. Only the $schema URL changes between them; the inferred type, properties, items, required and format keywords are the same.

Why is a field not marked as required?

A key is required only when it appears in every sample and in every object of an array. Keys missing anywhere are treated as optional. Untick Mark keys present in every sample as required to leave required out entirely.

More Data Tools

Related tools