# Generate a JSON Schema from a document you already have

Writing a schema from scratch for an existing payload is transcription work. Generate the first draft from the data, then tighten the parts that matter.

## Drafts

Both **draft 2020-12** and **draft-07** are supported. Pick 2020-12 for anything new; pick draft-07 when the consumer is an older validator or an OpenAPI 3.0 toolchain that has not moved.

## What gets inferred

| Setting | Default | Effect |
| --- | --- | --- |
| Required array | on | Keys present in every observed object become `required`. |
| Integer narrowing | on | `type: "integer"` when no fractional value was seen in that slot. |
| Format detection | on | Attaches `format` when every sampled string in a slot agrees — date-time, uuid, email, uri and similar. |
| Enum detection | on | Attaches `enum` when a slot behaves like a closed set, up to the enum limit. |
| Constraints | off | Adds `minItems` / `maxItems` / `minLength` / `maxLength` from the observed range. |
| Closed objects | off | Adds `additionalProperties: false` to every object. |

> Leave constraints and closed objects off for a schema meant to validate future documents. Bounds derived from one sample reject the next perfectly valid payload that happens to be longer.

## A workflow that holds up

1. Capture a representative response — ideally several, concatenated as [NDJSON](/jsonl-viewer) so the generator sees real variation.
2. Generate the schema and read it. The parts that surprise you are the parts where your mental model of the API is wrong.
3. Delete the constraints you cannot defend, and add the ones the documentation promises but the sample did not happen to exercise.
4. Commit it and validate in CI with Ajv or an equivalent. The schema is now a contract test that fails when the upstream API changes shape.

[Open the viewer](https://jsonparse.online/)

## Frequently asked questions

### Which draft should I choose?

Draft 2020-12 unless something downstream forces otherwise. Draft-07 remains the safer choice for OpenAPI 3.0 tooling and for older validators that never implemented the 2019-09 or 2020-12 keyword changes.

### Will the generated schema validate other documents of the same type?

With the defaults, usually yes, because constraints and additionalProperties: false are off. Turn those on and the schema describes your sample rather than your data model, and will reject valid documents.

### How does it decide something is an enum?

A string slot whose distinct values stay at or below the enum limit across every occurrence is treated as a closed set. Raise the limit for larger vocabularies, or switch it off when a slot is genuinely free text that happens to repeat.

---

Source: https://jsonparse.online/json-schema-generator
Last updated: 2026-09-14
JSONParse — Read, search and type huge JSON in your browser
