JSON to JSON Schema

Infer a JSON Schema (draft-07/2020-12) from sample JSON.

The JSON to Schema generator infers a JSON Schema from a sample JSON document. It works out types, nested properties, array item types and common string formats, and can mark keys that appear in every sample as required. Use it to bootstrap a schema for validation or API documentation, then refine it by hand.

What is JSON Schema?

JSON Schema is a vocabulary for describing the structure of JSON data: which properties an object has, which are required, and what type each value must be. Tools use schemas to validate incoming data, generate forms and document APIs. Writing a schema from scratch is tedious, so a common shortcut is to infer one from an example. The generator looks at the sample and records the type of every value (string, integer, number, boolean, null, object or array), the properties of nested objects, and the item type of arrays. When an array holds several objects, their shapes are merged: a key counts as required only if it appears in every object. A schema inferred from one sample describes only that sample, so it usually needs review.

How to use JSON to JSON Schema

  1. Paste a sample Paste a JSON object or an array of objects into the Sample JSON box.
  2. Choose the draft Select Draft-07 or 2020-12 in the Draft option.
  3. Decide on required Keep or untick Mark keys present in every sample as required.
  4. Copy the schema Copy the JSON Schema output or use Download to save it as schema.json.

Frequently asked questions

Is the generated schema ready to use for validation?

It is a starting point. It describes only what appeared in your sample, so check types, required lists and formats, and add constraints such as enums or length limits yourself.

What is the difference between Draft-07 and 2020-12?

They are different versions of the JSON Schema specification. This tool sets the $schema URI for the chosen draft; the generated keywords (type, properties, required, items, format) are valid in both.

Which formats are detected?

date-time (an ISO 8601 timestamp with a time zone), date (YYYY-MM-DD), email and uuid.

How are mixed types represented?

As a type list, for example ["string","null"]. If integers and decimals both occur, the type is number.

Is my JSON sent to a server?

No. The schema is generated in the page and the sample is not sent anywhere.