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
- Paste a JSON document or open a .json file.
- Set the title and choose the draft.
- Toggle formats, additionalProperties and examples.
- Copy the schema or download schema.json.