JSON Schema Generator
Turn one or more JSON examples into a draft 2020-12 JSON Schema: types, required keys and formats inferred only where every example agrees.
JSON examples
JSON Schema (2020-12)
Paste one or more JSON examples to get a schema. The more examples, the more exact the schema: a key is required only when every example has it.
Runs in your browser — nothing you enter leaves this device.
About this tool
What it does
This tool reads JSON examples, such as a few responses from an API, and writes a JSON Schema (draft 2020-12) that describes them. It works out the type of every field, lists which keys are required, describes the items inside arrays, and spots common string formats such as dates, email addresses and UUIDs. It is careful rather than clever: a key is only marked required when every example has it, a format is only claimed when every value of that field fits it, and a field that is a number in one example and a string in another gets both types instead of a guess. Numbers are read exactly as written, so an ID with twenty digits or a value written 1.0 is typed the way JSON Schema itself would type it.
How to use it
- Paste one JSON example, or an array holding several.
- If you pasted an array of examples, switch on “A top-level array is a list of examples”, so each element is treated as its own example rather than the whole array being one value.
- Choose whether keys every example has should be required, whether to detect formats, and whether objects should forbid keys the examples never had.
- Give the schema a title if you like; it appears at the top.
- Copy the schema or download it as schema.json, then check it against more data in the JSON Schema Validator.
Limits and your data
- Examples up to 5 MB are read.
- The schema can only describe what the examples show. A field that is always a string in your examples is typed as a string, even if the real API sometimes sends a number — add an example of that case and the schema will allow both.
- Enumerations, minimums, maximums and string lengths are not inferred: a handful of examples cannot tell a fixed list of values from a coincidence. Add those rules by hand.
- Formats detected are date-time, date, email, uuid, ipv4 and uri. Other formats in the standard, such as hostname or ipv6, are not guessed.
- Your JSON stays in this page. Nothing is uploaded, and the examples are only kept on this device if you have recent inputs switched on.
Questions
Why is a key not marked as required?
At least one of your examples does not have it. With a single example every key is required, which is often too strict, so give the tool two or three real examples — including one with optional fields left out — for a schema that fits the data you actually receive.
Why does a field say "type": ["string", "null"]?
It was a string in some examples and null in others. JSON Schema allows a list of types, and this is the plainest way to say the field may be empty.
Why is 1.0 typed as an integer?
Because the JSON Schema specification says so: a number is an integer when its value has no fractional part, however it is written. 1.5 is a number; 1.0, 1 and 1e3 are integers.
Which draft does the schema use, and will my validator accept it?
Draft 2020-12, the current version, named in the $schema keyword. The generated schema only uses keywords that have not changed since draft-07 — type, properties, required, items, format and additionalProperties — so older validators read it the same way if you change the $schema line.
Can I get TypeScript types instead?
Yes — JSON to Types turns the same kind of example into TypeScript interfaces or a Zod schema.