oktools

JSON Schema Validator & Generator

Validate JSON against a JSON Schema — draft 4, 6, 7, 2019-09, 2020-12 or OpenAPI — and see every error on its line, with the path, the failing keyword and what was expected. Typos in the schema itself are caught too. Or paste example JSON and generate a schema from it, with required fields, nullable values and formats worked out from the data. Everything runs in your browser and nothing is uploaded.

2020-12

Result

3 errors in the data

  • $.customer.email "ada.lovelace" is not a valid email

    format
  • $.items[1].quantity 0 is below the minimum of 1

    minimum
  • $.status "refunded" is not one of "pending", "paid", "shipped"

    enum

What changed between JSON Schema drafts

FeatureDraft 4Draft 6 / 72019-09 / 2020-12
Exclusive boundsexclusiveMinimum: true beside minimumexclusiveMinimum: 5, a number of its own
Tuplesitems: [ … ] with additionalItems2020-12: prefixItems, with items for the rest
Reusable partsdefinitions$defs
Keywords beside $refIgnoredApplied as well
DependenciesdependenciesdependentRequired, dependentSchemas
Conditionals—Draft 7: if / then / elseif / then / else, unevaluatedProperties
const, contains—Yes
formatAn assertionAn annotation unless the validator opts in

How it works

Both panes are read on every keystroke. The schema’s $schema URI picks the dialect — draft 4, 6, 7, 2019-09 or 2020-12 — or you pick one by hand, including the OpenAPI 3.0 and 3.1 flavours, and that choice decides what the keywords mean: exclusiveMinimum as a boolean or a number, items as a tuple list or prefixItems, dependencies or dependentRequired, whether nullable: true is honoured, and whether the keywords beside a $ref count at all. The data is then walked against the schema, and each failure is recorded with its path in the data, the keyword that failed and a sentence saying what was expected.

Paths matter because an error needs a line. Both texts go through the same YAML document model the OpenAPI validator uses, which keeps the line of every value, so $.items[1].quantity is also Line 9, with a mark in the gutter and a button that selects it. anyOf and oneOf do not list every branch’s complaints: the option that came closest is chosen and its own reason given. References — JSON Pointers, $id and $anchor — are followed inside the schema, recursion included, and the schema itself is linted for keywords that do not exist, types that are not types, bounds no value can meet and references that point nowhere.

Generate mode works the other way round. Every value seen at one place in the example is merged into a single shape: the set of types, the properties and how many objects had each, the item shape of arrays, and which string formats every string there satisfied. The shape is then written out as a schema in the draft you chose. A property is required only when every object had it, a field that was sometimes null gets "null" in its type list, and a format is kept only if the validator agrees with it, so the data always passes the schema made from it.

Examples

Validate JSON against a draft 2020-12 schema

This is the page’s sample data checked against its sample schema: an order whose email has a format, whose item quantity has a minimum of 1 and whose status is an enum. Each line names the path in the data, the keyword that failed and the line to jump to, so the three mistakes are found without reading the schema.

Data
{
  "id": "ord_7f3k2m9q",
  "customer": {
    "name": "Ada Lovelace",
    "email": "ada.lovelace"
  },
  "items": [
    { "sku": "BOOK-001", "quantity": 2, "price": 12.5 },
    { "sku": "PEN-042", "quantity": 0, "price": 1.2 }
  ],
  "status": "refunded",
  "placedAt": "2026-10-17T09:30:00Z"
}
Result
3 errors in the data
$.customer.email "ada.lovelace" is not a valid email — format — Line 5
$.items[1].quantity 0 is below the minimum of 1 — minimum — Line 9
$.status "refunded" is not one of "pending", "paid", "shipped" — enum — Line 11

Catch a typo in the schema itself

JSON Schema ignores keywords it does not know, which is how a schema with requried in it accepts everything. The lint lists what would be silently skipped, with the keyword probably meant, and the two mistakes that make the age property unsatisfiable. The data pane, meanwhile, reports only that age must be integr.

Schema
{
  "type": "object",
  "requried": ["email"],
  "properties": {
    "email": { "type": "string", "format": "e-mail" },
    "age": { "type": "integr", "minimum": 18, "maximum": 17 }
  }
}
Problems in the schema
"requried" is not a keyword, so it is ignored. Did you mean "required"? — requried — Line 3
"e-mail" is not a format this validator checks, so any string passes it. — properties › email › format — Line 5
"integr" is not a type. Use one of string, number, integer, boolean, object, array, null. — properties › age › type — Line 6
minimum is greater than maximum, so no value can pass. — properties › age › minimum — Line 6

Generate a schema from example JSON

Two samples are merged with the default options. colour appears in one object only, so it is described but not required; sku is null in one and text in the other, so its type is a list; price is an integer in one sample and a decimal in the other, so it becomes number. The options add additionalProperties: false, examples, or another draft.

Example JSON
[
  { "id": 1, "name": "Desk lamp", "price": 49.9, "tags": ["home"], "sku": null },
  { "id": 2, "name": "Chair", "price": 129, "tags": [], "sku": "CH-2", "colour": "oak" }
]
JSON Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "id": {
      "type": "integer"
    },
    "name": {
      "type": "string"
    },
    "price": {
      "type": "number"
    },
    "tags": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "sku": {
      "type": [
        "string",
        "null"
      ]
    },
    "colour": {
      "type": "string"
    }
  },
  "required": [
    "id",
    "name",
    "price",
    "tags",
    "sku"
  ]
}

Read why a oneOf failed

Instead of one error per branch, the branch that got furthest is named with its own reason. The card branch fails only on the pattern; the iban branch fails earlier, on a missing required property, so it is left out of the message.

Schema and data
Schema:
{
  "oneOf": [
    {
      "type": "object",
      "required": ["card"],
      "properties": { "card": { "type": "string", "pattern": "^\\d{16}$" } }
    },
    {
      "type": "object",
      "required": ["iban"],
      "properties": { "iban": { "type": "string" } }
    }
  ]
}

Data:
{ "card": "1234" }
Result
1 error in the data
$ matches none of the 2 oneOf options; the closest fails because $.card "1234" does not match the pattern ^\d{16}$ — oneOf

Supported formats

  • JSON Schema draft 4 to 2020-12Detected from $schema or chosen by hand; each draft’s own spelling of exclusive bounds, tuples, definitions against $defs, dependencies and the keywords beside a $ref is honoured, with unevaluatedProperties, if/then/else, $anchor and $id all supported.
  • OpenAPI 3.0 and 3.1 schemasThe 3.0 flavour accepts nullable: true and a single type; 3.1 is JSON Schema 2020-12 as it stands. Pick one to see a schema the way your API tooling reads it.
  • Checked formatsdate, time, date-time and duration with real calendar dates, email, idn-email, hostname, ipv4, ipv6, uri, uri-reference, iri, uuid, json-pointer, relative-json-pointer and regex. Any other format is reported in the schema lint as unchecked.
  • YAML as well as JSONEither pane accepts YAML, so a schema kept beside an OpenAPI document validates without converting it first; files up to 10 MB can be opened or dropped in.
  • Generated schema outputDraft 2020-12, draft 7 or draft 4 with the matching $schema URI and example keyword, copied to the clipboard or downloaded as schema.json.

Use cases

  • Check an API response against its schemaPaste the schema from the OpenAPI components and the body from the network tab to see exactly which field broke the contract, and in which keyword.
  • Validate a configuration file before deploying itA YAML or JSON config checked against its schema fails here on a mistyped key or a value out of range, with the line to fix, before a server fails on it.
  • Write a schema for data you already haveGenerate from a few real records, tighten the result with enum, minimum and additionalProperties: false, then validate the records against it with one click.
  • See what changed between draftsSwitch the version on the same schema and data to watch a tuple, an exclusiveMinimum or a $ref with siblings behave differently from one draft to the next.
  • Debug a schema that passes everythingThe schema lint finds the misspelt keyword, the unknown type or the required: true on a property that made the schema accept any input.

Limitations

  • No network for referencesA $ref to another file or a URL is reported as one that could not be followed. Inline the referenced schema under $defs, or bundle the files, before validating.
  • Formats are checked strictly2019-09 and later treat format as an annotation, so a conformant validator in your stack may accept what this one rejects. Untick Check formats to compare the two results.
  • Inference describes the samples, not the intentA generated schema carries no minimum, maxLength, pattern or enum, because a few samples cannot say what the rule is. Add those by hand before relying on it.
  • One schema, one documentThere is no batch mode for many files, and custom keywords or vocabularies are not understood: they are flagged by the lint and ignored by the validator.
  • Large inputsFiles above 10 MB are refused, and both panes are checked on every keystroke, so a very large document is best pasted in one go rather than edited in place.

Frequently asked questions

How do I validate JSON against a JSON Schema?

Paste the schema on the left and the JSON on the right; it is checked as you type. Each error says where in the data it is — as a path like $.items[1].quantity and as a line you can jump to — which keyword failed, and what was expected, such as "0 is below the minimum of 1". The lines with errors are marked in the editor's gutter. Both boxes also accept YAML, and you can open files or drop them in.

Which JSON Schema versions are supported?

Draft 4, 6 and 7, 2019-09 and 2020-12, plus the OpenAPI 3.0 and 3.1 flavours. The version is read from the schema's $schema, or chosen by hand. The differences are respected: exclusiveMinimum as a boolean in draft 4 and a number later, items as a tuple list up to 2019-09 and prefixItems in 2020-12, dependencies versus dependentRequired, and whether keywords beside a $ref count (only from 2019-09). unevaluatedProperties, if/then/else, $defs, $anchor and $id all work. References are followed inside the schema but never fetched from the network.

How do I generate a JSON Schema from JSON?

Switch to Generate and paste example JSON. Every value at the same place is merged into one description, so an array of objects gives one item schema covering them all: a property is required only when every object has it, a field that is sometimes null gets "null" in its type, integers stay integers unless a decimal appears, and formats such as date-time, email and uuid are kept when every string has them. Choose the draft, whether to close objects with additionalProperties: false, and whether a top-level array is a list of samples; then "Validate with this schema" checks your data against it.

Why does my schema accept data it should reject?

Usually a keyword the validator does not know, which JSON Schema silently ignores — a typo such as "requried" or "minLenght", or "required": true written on a property instead of a list on the object. The tool lists those under Problems in the schema with the keyword it thinks you meant. Other common causes: forgetting additionalProperties: false, so unknown fields pass; a "type" missing, so any type passes; or keywords next to a $ref in draft-07 or older, which are ignored there.

Are formats like email and date-time checked?

Yes, by default: date, time, date-time (with real calendar dates, so February 30 fails), duration, email, hostname, ipv4, ipv6, uri, uuid, json-pointer and regex. Since 2019-09 the specification treats format as an annotation that validators may skip, so a strict 2020-12 validator in your stack might accept what this one rejects; untick "Check formats" to see the result without them.

What is the difference between a JSON Schema and an OpenAPI schema?

OpenAPI 3.1 uses JSON Schema 2020-12 as it is. OpenAPI 3.0 used a variant of draft 4 with differences: nullable: true instead of "null" in the type, a single type rather than a list, no const, examples or $defs, and exclusiveMinimum as a boolean. Pick OpenAPI 3.0 as the version to validate a 3.0 schema the way your API tooling will read it. To check a whole OpenAPI document rather than one schema, use the OpenAPI validator.

Is my data uploaded anywhere?

No. Validation and schema generation are JavaScript running in your browser, so the schema and the data — customer records, configuration, anything — never leave your device and are not stored. You can check by opening the network tab and watching it stay empty while you work.