How to Generate a JSON Schema

How to Generate a JSON Schema

A JSON Schema is a document that describes the shape of your JSON: which fields exist, what type each one is, and which are required. If you have a sample payload and want to validate future data against it, the fastest path is to generate a starting schema from the example, then tighten it by hand. Here is how that works.

What JSON Schema is for

JSON Schema is a standard vocabulary for describing JSON data. Instead of checking fields one by one in code, you write a schema once and use a validator to confirm any payload matches it. The same schema works across languages, so a Python service and a JavaScript client can agree on exactly what valid data looks like.

Common uses:

  • API validation: reject malformed request bodies and verify response shapes.
  • Config validation: catch typos and missing keys before an app boots.
  • Form and UI generation: drive form fields and editors from the schema.

The core keywords you will see:

  • type: the data type, like string, number, object, array, or boolean.
  • properties: the named fields inside an object and the schema for each.
  • required: an array of property names that must be present.
  • items: the schema each element of an array must match.
  • enum: a fixed list of allowed values for a field.

Not the same as schema.org

One common mix-up: JSON Schema is not JSON-LD or schema.org structured data. Schema.org markup describes the meaning of page content for search engines, embedded as JSON-LD. JSON Schema describes the structure of arbitrary JSON for validation. Different problems, different tools. This post is about the validation kind.

Generate a JSON Schema in four steps

A generator reads your sample and infers a reasonable draft. It cannot read your mind, so treat the output as a first pass you will refine.

  1. Open the JSON Schema Generator and paste a representative JSON example.
  2. Read the generated schema. It infers a type for every value and builds properties for each object key, with items for arrays.
  3. Tighten the draft. Mark fields as required where they must always appear, swap loose types for an enum where only certain values are valid, and add constraints like minLength, minimum, or string format (email, date-time, uri).
  4. Copy the finished schema and drop it into your validator (Ajv, jsonschema, and friends all read the same format).

The JSON Schema Generator runs entirely in your browser, so your sample data never leaves your device. A generator infers structure, but it cannot know your business rules, so the refining step is where a useful schema is actually made.

Start from a real example, let the generator draft the structure, then tighten the rules until invalid data has nowhere to hide.

← All posts