Developer Tools

JSON to JSON Schema generator.

Paste one or more sample JSON documents and get a draft 2020-12 JSON Schema: types, required properties, string formats and merged array items. Runs entirely in your browser.

Advertisement

Sample JSON

JSON Schema

Paste sample JSON to generate a schema.

How the schema is inferred

Every sample value at the same position is grouped by JSON type. One type gives "type": "string"; several give a type array such as ["string", "null"]. When integers and non-integers both appear, the result is number, since every integer is also a number.

For objects, properties seen in any sample are listed, and a property is required only if it appears in every object sample at that position. For arrays, the items of every array are pooled and inferred together, so object elements are merged into one items schema. An empty array adds no items constraint.

String formats are only set when every string at that position matches the same format. The names come from section 7.3 of the validation specification. Note that in draft 2020-12, format is an annotation by default; a validator only enforces it if you turn that on. Enums are optional and only proposed when the distinct values are few and at least one repeats.

Sources: JSON Schema 2020-12 core, JSON Schema 2020-12 validation (keywords type, required, enum, format), RFC 3339 (date and time formats).

Frequently asked questions

Is the generated schema final?

No. It describes only the samples you gave it. A field that happened to appear in every sample is marked required, and a value type that never appeared is not allowed. Review the result and tighten or loosen it before using it in production.

Why is 1.0 treated as an integer?

JSON parsers, including this page's, read 1.0 and 1 as the same number. If you need decimals everywhere, untick "Use integer for whole numbers" and every number becomes number.

How do I supply several samples?

Put one complete JSON document per line, or paste a single top-level array and tick "Treat a top-level array as a list of samples". A single document spread over several lines is treated as one sample.

Processed entirely in your browser

Your JSON is parsed and analysed locally. Nothing is uploaded or stored. Format detection is a pattern check for schema hints, not proof that an email address or URL exists.

Advertisement
Advertisement
Listening…