Generate a JSON Schema from representative sample data
A JSON Schema describes the shape and rules of JSON data so a validator can check whether a document meets them. This generator infers a Draft 2020-12 schema from one JSON value. Use it to get a starting point for an API response, configuration object, or dataset, then review the inferred rules before relying on them.
Paste JSON or open a local file up to 10 MiB. Set a title, optionally add an absolute HTTP or HTTPS $id, and select Generate Schema. The result can be copied or downloaded as schema.json.
Use multiple examples to find optional and nullable fields
A single object only shows one case: every property present in that sample will be marked required. To learn which fields vary, provide an array containing several representative objects. The generator marks a property required only when it appears in every sampled object at that level.
[
{ "id": 101, "name": "Ada", "active": true },
{ "id": 202, "name": "Grace", "active": false, "nickname": null },
{ "id": 303, "name": "Katherine", "active": true, "nickname": "Kat" }
]
From these examples, id, name, and active are required for each item. nickname is optional because it is missing from one object, and its inferred type allows both a string and null because both values appear. This gives the schema evidence about variation that a single sample cannot provide.
What the generator infers
- Types: Strings, Booleans, nulls, integers, numbers, objects, and arrays are inferred from observed values. If a field has more than one observed type, the schema can include multiple allowed types or an
anyOfdefinition. - Nested properties: Objects inside objects or arrays are described recursively.
- Array items: A non-empty array gets an item schema inferred from its contents. An empty array has no evidence about its items, so its generated
itemsschema is unconstrained. - Required properties: A property is required only when it appears in every sampled object at the same level.
- Additional properties: By default, the generated schema permits unlisted object properties. Selecting Disallow additional properties adds
"additionalProperties": falseto generated object schemas, including nested objects.
How to generate and refine a schema
- Paste a representative object, array, or other valid JSON value. For variable records, use an array with examples that show the differences you expect.
- Choose a descriptive schema title. Add a
$idonly if you have an absolute HTTP or HTTPS identifier to use. - Leave additional properties allowed if records may gain new fields. Enable the restriction only when the object shape should be closed.
- Select Generate Schema, then inspect the root type, property count, required fields, and generated definitions.
- Refine the result for rules that cannot be learned from examples, then copy or download the schema.
Use the JSON Schema Validator to check sample data against the generated schema. Validation can confirm the rules you wrote; it cannot determine whether those rules match your application's business requirements.
What sample-based generation cannot decide
Examples show observed values, not every value your system should accept. The generator does not infer business rules such as numeric minimums or maximums, string formats, regular-expression patterns, enumerated values, or array length limits. Add those constraints from the API contract or application requirements.
Check required fields carefully: if a sample is incomplete, a field may be inferred as optional even when production records must include it. Conversely, a field present in every sample may be marked required even if it is optional in the real data. Generated schemas are a draft to review, not proof that the examples represent every valid case.
Frequently asked questions
Which JSON Schema draft does it generate?
It outputs a schema using the JSON Schema Draft 2020-12 meta-schema URI.
Why should I provide an array of objects?
Several records help the generator distinguish fields that always appear from fields that are missing in some examples. Include examples with optional, null, and alternate-type values when those cases are valid for your data.
Does a missing field mean the field is nullable?
No. A missing property affects whether it is listed as required. A property that is present with null contributes the null type. A property may be optional, nullable, both, or neither.
What happens with an empty array?
The generator cannot infer the item type from an empty array, so it creates an unconstrained items schema. Add representative items or refine the schema yourself.
What does Disallow additional properties do?
It adds additionalProperties: false to object schemas so unlisted fields fail validation. Keep it off if future or application-specific fields should be accepted.
Does the generated schema include every validation rule?
No. It infers structure and observed types, but you need to add application-specific rules such as formats, ranges, patterns, and allowed values.
Is my sample JSON uploaded?
The generator parses the sample and creates the schema in your browser. Its script does not send the JSON input to a server.