JSON Schema Generator

Generate a JSON Schema Draft 2020-12 definition from sample JSON. Infer nested objects, array items, data types, and fields consistently present across your examples.

Sample JSON

0 characters

Generated JSON Schema

Generated JSON Schema appears here.

Paste JSON or load a sample to begin.

How schema generation works

Properties and types are inferred from the values in your sample. A property is marked required only if it appears in every sampled object at that level. Nulls are included as allowed values, and an empty array gets an unconstrained items schema. Generated schemas describe the examples, so adjust constraints such as ranges and formats for your application.

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

How to generate and refine a schema

  1. Paste a representative object, array, or other valid JSON value. For variable records, use an array with examples that show the differences you expect.
  2. Choose a descriptive schema title. Add a $id only if you have an absolute HTTP or HTTPS identifier to use.
  3. Leave additional properties allowed if records may gain new fields. Enable the restriction only when the object shape should be closed.
  4. Select Generate Schema, then inspect the root type, property count, required fields, and generated definitions.
  5. 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.