Generate JSON Schema from JSON
Turn sample JSON into a JSON Schema draft with type, properties, items and required already filled in
Your data stays with you. Conversion happens inside the browser; nothing is sent to a server.
Did this tool do the job?
Thanks, your feedback came through.
How it works
A JSON Schema is a rules file that says which fields a JSON document must have and what types they hold; it is used to validate API requests or configuration files. Instead of writing one from a blank page, paste a real sample into the left pane and a schema with type, properties, items and required filled in appears on the right. In the sample, the "supplier" object gets its own properties block and the "variants" array is described with items. The records of an array are merged into one schema: "onSale" appears only in the second variant, so it is left out of required, while "size_in" and "color" are in both and are required. 34.99 becomes number and 12 becomes integer; a field that is only ever null, like "note", gets type null. When a string matches the date-time or email format exactly, a format is added. The result is a draft: rules such as allowed values (enum), a lower bound (minimum) or a pattern have to come from you, because only you know the data.
This tool is also known as json to json schema, json schema generator, generate json schema from json, json schema from example, infer json schema.
What is JSON Schema?
JSON Schema is a rule language that describes the structure of a JSON document in JSON itself: which fields must exist (properties, required), their types (type), the items of an array (items) and value limits (minimum, pattern, enum). A validator library reads the schema, compares incoming data against it and reports every mismatch with its path. OpenAPI documents and the autocomplete of many editors are built on it.
What is required vs. null?
In JSON Schema, required says that a field must be present in the object; it says nothing about the field's value. So in {"note": null} the note field exists and satisfies required, and its type must also include null for the value to pass. A missing field and a field set to null are two different cases, and this tool marks them separately.
What is the difference between a JSON Schema and sample JSON?
Sample JSON is a single piece of data: it shows one order as it is right now. A JSON Schema writes the rule every order must follow: which fields are mandatory, of which type, within which range. Inferring a schema from a sample gives you the skeleton of that rule, but it cannot know cases the sample does not show (another currency, an empty list, a very long name). That is why someone who knows the real rules should review the generated schema and add the limits.
How the schema is inferred: merging, null and mixed types
The tool writes only what it sees. All records of an array are merged into a single schema; a field present in every record goes into required, and a field missing from even one record does not. A field seen as null stays required but gets null added to its type: "type": ["string", "null"]. If a field shows two types (a number in one record, text in another), the schema accepts both with anyOf. When whole and decimal numbers are mixed, the shared type is number.
An empty array tells nothing about its items, so items: {} is written, which means any value is allowed. A format for date, date-time or email is added only when every value of the field matches exactly; an impossible day such as 2026-02-30 gets no format. In Draft 2020-12, format is only an annotation by default; turn on format checking in your validator (for example ajv-formats with Ajv).
- {"a": 1} → "a": {"type": "integer"}, "required": ["a"]
- [1, "x"] → "items": {"anyOf": [{"type": "string"}, {"type": "integer"}]}
- [] → "items": {}
- {"t": "2026-09-27T10:30:00-05:00"} → "format": "date-time"
Which draft to pick and where to use the schema
Draft 2020-12 is the current version; OpenAPI 3.1, VS Code's JSON validation and current releases of Ajv and Python's jsonschema support it. If your tool only knows draft-07 (older Ajv versions, some code generators), pick Draft-07. In this tool the two outputs differ only in the $schema line, because the keywords used (type, properties, items, required, anyOf, format) mean the same in both.
Use the schema to validate API requests on the server, to add autocomplete and error markers to a configuration file in your editor, or to document a data file's shape for your team. An empty required list gives a loose schema that allows missing fields, which suits cases where you only want to check types.
Frequently asked questions
How do I generate a JSON Schema from JSON?
Paste an example of the data you want to validate into the left pane on this page. The right pane shows a schema with type, properties, items and required filled in. Copy or download it, then add data-specific rules such as enum, minimum or pattern yourself.
Which fields end up in the required list?
Fields that appear in every record of the sample. A field missing from even one record of an array is treated as optional. A field whose value is null stays required, but null is added to its type. If you want no field to be mandatory, set the required option to Leave empty.
What is the difference between draft-07 and 2020-12?
2020-12 is newer and adds features such as prefixItems for position-by-position array items and $defs. This tool only uses keywords that behave the same in both, so the output is identical apart from the $schema line; choose the draft your validator supports.
Is the JSON I paste sent to a server?
No. The schema is inferred entirely in your browser, so even a sample with customer records or internal data never leaves this page. Once loaded, the page also works offline.