Tools / JSON Schema Generator

JSON Schema Generator.

Generate a draft 2020-12 JSON Schema from sample JSON, with required fields, formats and merged array items.

Runs in your browser

Ctrl/⌘ + Enter to run · Ctrl/⌘ + Shift + C to copy the result

Result

About JSON Schema Generator

The JSON Schema Generator writes a first version of a schema for you from a real example of the data, such as an API response, a webhook payload or a config file. It walks the whole document and records the type of every value: integer or number, string, boolean, null, object or array. Objects get their properties in the order they appear, and arrays get a single items schema that merges every element, so a list of orders where only some have a "note" produces one order schema in which note is optional. Required fields are inferred from the sample: a property is required only when it appears in every object at that position. Values that are sometimes null produce a type list such as ["string", "null"], and a field that holds both 1 and 1.5 becomes number. With format detection on, strings that all look like an ISO 8601 date-time, a date, a UUID, an e-mail address, an http(s) URL or an IPv4 address get the matching format keyword. Switch on strict mode to add additionalProperties: false everywhere, which is useful for request bodies, and add example values to make the schema self-documenting. The result targets draft 2020-12, so you can paste it straight into the JSON Schema Validator next door, into an OpenAPI 3.1 document or into Ajv. Treat the output as a starting point. One sample cannot tell the generator that a string is really an enum, that a number has a maximum, or that an empty array should contain objects; tighten those rules by hand. The more varied the sample (for example an array with several records), the better the guesses. Nothing is uploaded.

How to Use

  1. Paste a representative JSON sample, ideally with several array items.
  2. Pick the options: required fields, strict mode, formats and examples.
  3. Copy the schema and refine enums, limits and descriptions by hand.

Frequently Asked Questions

How are required fields decided?

A property is required when it appears in every object of the same shape in your sample. In an array of objects, a key missing from any element is optional.

Why is my empty array schema missing items?

An empty array gives no information about its elements, so the generator writes only "type": "array". Add one example element to get an items schema.

Which JSON Schema version is produced?

Draft 2020-12, declared with $schema. The keywords used (type, properties, required, items, format, additionalProperties) also work in draft-07 and OpenAPI 3.1.

Is my JSON sent anywhere?

No. The schema is generated in your browser.

Related Tools