Generate a JSON Schema from sample data — and test it
Writing a JSON Schema by hand is slow and error-prone. This JSON Schema generator infers one from an example document: types for every field (with integers distinguished from decimals), nested objects and arrays, the required list, string formats such as date-time, email and uri, and enums for small sets of repeated values like order statuses. Arrays of objects are merged, so a property that appears in only some items is optional and a field that is sometimes null becomes ["string", "null"].
The second tab is a JSON Schema validator. Paste any instance and schema — generated here or written by hand — and get every error with its JSON Pointer path and the keyword that failed. It implements the commonly used parts of draft 2020-12 and draft-07: types, properties, required, additionalProperties, items/prefixItems, enum, const, numeric and length limits, pattern, format, allOf/anyOf/oneOf/not, if/then/else and local $ref.
Inference and validation run in your browser, so API payloads and private data never leave your device.
How to use the JSON Schema Generator
- Paste a representative JSON document into Sample JSON, load a
.jsonfile, or press Example. Arrays with several items give the best results. - Choose the Draft (2020-12 or draft-07), an optional Title and how Required properties are decided.
- Toggle format detection, enums,
additionalProperties: falseand examples. The schema updates instantly. - Copy or download the schema, then review it: tighten enums, add
minimum/maxLengthlimits and descriptions that a sample cannot reveal. - Press Validate with this schema (or open Validate JSON), paste the data to check and press Validate.
JSON Schema Generator features
Smart type merging
Values seen across array items are combined: 1 and 2.5 give number, a value that is sometimes null gives a type array, and genuinely mixed structures produce anyOf.
Required from evidence
By default a key is required only if it appears in every object sampled at that position — or choose “every key” or “none”.
Format and enum detection
ISO 8601 date-times, dates and times, emails, URIs, UUIDs and IPv4 addresses get a format; repeated short strings (at most six distinct values) become an enum.
A real validator
Errors carry the JSON Pointer path (/orders/1/status) and the failing keyword. format can be treated as an assertion or, as the 2020-12 spec defaults, as an annotation.
Both current drafts
Draft 2020-12 ($defs, prefixItems, siblings next to $ref) and draft-07 (definitions, tuple items, additionalItems) are detected from $schema.
How the generator infers each keyword
| In the sample | In the schema |
|---|---|
42, -7 | "type": "integer" |
9.5 anywhere in the same field | "type": "number" |
"2026-10-17T09:30:00Z" | "type": "string", "format": "date-time" |
"paid", "paid", "refunded" | "enum": ["paid", "refunded"] |
a field that is null in some items | "type": ["string", "null"] |
| a key missing from some objects | left out of required |
[] (empty array) | "items": {} — any item allowed |
Validator coverage and limits
The validator implements the keywords most schemas use. Not supported: remote $refs to other files or URLs, $dynamicRef, unevaluatedProperties/unevaluatedItems, dependentSchemas and content keywords. Formats checked when assertion is on: date-time, date, time, email (simplified), uri, uuid, ipv4, ipv6, hostname and regex. For production use, run the same schema through a full implementation such as Ajv in your build or API.
- Draft is chosen from
$schema: URLs containing draft-04 to draft-07 use draft-07 rules; everything else uses 2020-12. - In draft-07, keywords next to a
$refare ignored, as that draft specifies; in 2020-12 they apply too. - String lengths count Unicode code points, so an emoji counts as one character.
Where JSON Schemas are used
OpenAPI 3.1 uses JSON Schema 2020-12 for request and response bodies — inspect a spec with the OpenAPI viewer. Editors such as VS Code validate configuration files against a schema referenced by $schema; form builders and low-code tools generate UIs from it; and data pipelines use it to reject malformed records. Before inferring, tidy the sample with the JSON Formatter; to compare two versions of a payload, use JSON Diff.
JSON Schema Generator FAQ
How do I generate a JSON Schema from JSON?
Paste the JSON into the sample box. The JSON Schema generator infers types, nesting, required keys, formats and enums immediately; copy or download the result. Use a sample with several array items so optional fields and enums can be recognised.
Which draft should I choose?
Draft 2020-12 is the current version and the one used by OpenAPI 3.1. Choose draft-07 if your validator or tooling (some older libraries and editors) does not support 2020-12 yet.
Why is a field not in the required list?
Because it was missing from at least one object in the sample. Switch Required properties to “Every key” if every field is mandatory, or edit the list by hand.
Is format validated?
Optionally. JSON Schema 2020-12 treats format as an annotation by default, but many validators assert it. Tick or untick “Treat format as an assertion” to match the validator you use.
Can the validator follow $ref to another file?
No — only local references such as #/$defs/address or #/definitions/address are resolved, plus $anchor names. Bundle external schemas into one document first.
Is my data uploaded?
No. Both inference and validation are plain JavaScript running in this page.