JSON to JSON Schema Generator

Paste a JSON document and get a JSON Schema that describes it: types, required keys, array items and string formats.

Loading tool…

About the JSON to JSON Schema

The schema is inferred from the values of the document. Objects get properties and a required list, arrays get items, and numbers are integer or number; a value written as 1.0 counts as a number. A value that is null in some places gets a type list such as ["string", "null"]. The output declares $schema for draft 2020-12 or draft-07. The keywords used here mean the same in both drafts.

All items of an array are merged into one schema. A key is required only when every item has it, so optional fields are found by giving several samples in an array. When the items have different kinds, items becomes an anyOf with one schema for each kind. An empty array gives {"type": "array"} without items, because nothing is known about its content.

Options: Detect formats adds format when every string of a field is a date-time or date (RFC 3339), email, uri, uuid or ipv4. Validators treat format as an annotation unless format assertion is turned on. additionalProperties: false makes objects reject keys that are not in the sample, and Examples copies up to three sample values into examples. A schema cannot learn ranges, patterns or enums from one document, so add those by hand.

How to use it

  1. Paste a JSON document or open a .json file.
  2. Set the title and choose the draft.
  3. Toggle formats, additionalProperties and examples.
  4. Copy the schema or download schema.json.

Frequently asked questions

Which draft should I choose?
Draft 2020-12 is the current version and the one OpenAPI 3.1 uses. Choose draft-07 for tools that have not moved on, which is still common. The generated keywords work in both.
How does it know which properties are required?
A key is required when every object of that kind in the sample has it. With a single object, every key is required; put several objects in an array to show which keys can be missing.
What is the difference between integer and number?
"integer" accepts whole numbers only, "number" accepts any number. If a field held only whole numbers in the sample but can hold fractions, change its type to number.
Should I use additionalProperties: false?
It catches misspelled keys, but it also rejects every field that is added later. Use it for strict inputs such as configuration files, and leave it off for API responses that may grow.

Related tools