Format Code Now
/
ConvertJSON Schema Generator Next: JSON5 to JSON ›

JSON Schema Generator

CV-16

Paste a JSON sample and press Generate to get a JSON Schema for draft 2020-12. It describes the types, nested properties and array items of your sample, and you choose whether to mark keys as required.

Runs in your browser. Nothing is uploaded.

JSON sample

JSON Schema

How to use it

  1. Paste a JSON sample into the input box. Several objects in an array give a better result than one.
  2. Choose whether keys that appear in every object are marked required.
  3. Turn on Infer formats if you want date-time, email, uuid, uri, date, time or ipv4 added where every value matches.
  4. Press Generate, then copy or download the schema as a .json file.
  5. Tighten the schema by hand with limits, patterns and enums that the sample cannot show.

What the schema contains

The schema declares draft 2020-12 and describes the types it sees. Whole-number literals become integer, other numbers become number, and a key that holds a string in some items and null in others becomes a type list such as string and null. Nested objects get properties, and arrays get items. When array items have mixed shapes, the schema uses anyOf. An empty array gets no items rule.

Required keys and formats

With Mark keys in every object as required on, a key is listed as required only if every object in the sample has it. Formats are off by default. When on, a string key gets a format only if all its values match date-time, date, time, email, uuid, uri with :// or ipv4. These are simple pattern checks, not full validators, so review them. You can also add additionalProperties: false to reject unknown keys.

What a sample cannot tell

The schema describes the sample, not your data model. It does not guess minimum or maximum values, string lengths, patterns or enums, and it cannot know that a key is optional if the sample always contains it. A value of 1.0 in the sample is read as a number, not an integer. Use the output as a first draft and run your real documents against it.

Questions people ask

How do I generate a JSON Schema from JSON?

Paste a sample document and press Generate. The tool writes a draft 2020-12 schema with the types, nested properties, array items and required keys that the sample shows. Copy it or download it as a .json file.

Which JSON Schema draft does it use?

Draft 2020-12. The output starts with a $schema line pointing to https://json-schema.org/draft/2020-12/schema. Many validators support this draft, but older ones may only know draft-07 or earlier, so check which drafts yours accepts before you use the schema.

How does it decide which keys are required?

A key is required when it appears in every object that the sample holds at that position. In a single object all keys are required. Turn off the required option if you want to add that rule yourself.

What does Infer formats do?

It adds a format keyword such as date-time or email to a string key when all its sample values match that format. It checks by pattern only. A format keyword is an annotation in many validators, so enable format checking if you need it enforced.

Why is a number typed integer or number?

A literal without a decimal point or exponent, such as 5, becomes integer. One with a decimal point, such as 5.0 or 2.5, becomes number. If the sample mixes both, the key is typed number.

Can it add enums, minimum values or patterns?

No. A sample cannot show the allowed range or the allowed set of values, so the generator does not invent them. Add those rules by hand after generating the schema.

About this tool

Builds a schema that describes the sample you give it: types, nested properties and array items. It does not guess limits, patterns or enums, so tighten it by hand. With several objects in an array, a key is required only if every object has it. Whole-number literals become integer and others number, so 5.0 and 1e3 are number. Formats are off by default; when on, a string gets a format only if every value for that key matches date-time, date, time, email, uuid, uri (with ://) or ipv4, using a simple pattern, not a full validator. The output declares draft 2020-12.

Format Code Now: free, no ads, no accounts. Your input stays in your browser.