JSON Schema Generator
Operator: Abdulla Al Fahad. How tools are built and checked
A JSON Schema is the contract behind a lot of AI work: the response_format that keeps a model's reply in a fixed shape, the parameters block of a tool the model may call, and the check you run on whatever comes back. Writing one by hand for a record with thirty fields is slow, and the mistakes are predictable: a field marked required that some records leave out, an integer type on a value that is sometimes 12.5, a missing null on a field that is empty half the time.
This generator starts from the data instead. Paste two or more real records separated by a line holding only ---, or a whole array of them, and it writes a draft 2020-12 schema; in the default mode that schema accepts every record it learned from. It also tells you what it noticed along the way: which fields were missing from some records, which held more than one type, and which were always null, so the guesses it had to make are visible before you ship the schema.
Key features
- Learns from several samples at once, separated by --- lines, or from the elements of a top-level array
- required lists only the keys present in every object at that place, including objects inside arrays
- Integer and number told apart by how the value is written: 7 is an integer, 7.0 and 7e0 are numbers
- Array items merged across every element and every sample, with object properties combined
- Optional formats date-time, date, email, uri and uuid, added only when every value of a field qualifies
- Optional enums for short strings that repeat, off unless you turn them on
- Strict mode: every property required, additionalProperties false, and optional fields typed as [type, "null"]
- Output as a plain schema, a response_format json_schema object or a tool definition, ready to copy or download
Plain schema output and the two API wrappers
Input is JSON text, up to 2 MB, typed into the box or loaded from a .json file. Several samples go in one box with a line containing only --- between them; spaces around the dashes are allowed, and a line of four dashes is not a separator. A file whose top level is an array can be treated as a list of samples with the first option, which is the usual case for an API that returns [ {...}, {...} ]. Files must be UTF-8, or UTF-16 with a byte-order mark; ZIP, PDF and other binary files are refused with a message naming the problem.
The plain output starts with "$schema": "https://json-schema.org/draft/2020-12/schema" and uses only type, properties, required, items, anyOf, format, enum and, in strict mode, additionalProperties. Nullable fields are written as a type array such as ["string", "null"]. Fields that held several kinds of value become anyOf, with a {"type": "null"} branch when null was seen too.
Two wrappers are offered for AI APIs. The response_format choice writes {"type": "json_schema", "json_schema": {"name", "strict", "schema"}}, the json_schema form described in OpenAI's public API documentation at the time of writing. The tool choice writes {"name", "description", "parameters"}. Some APIs nest a tool under a function key or call the schema field input_schema, so move the parameters object to match, and check the current documentation of the API you call; this page cannot promise that any provider accepts a given schema. Names keep letters, digits, underscores and hyphens (anything else becomes an underscore) and stop at 64 characters, and the wrappers leave out the $schema line.
How it works
Each sample is read by a small parser built into the page rather than by JSON.parse, because JSON.parse turns 10.0 into 10 and the integer-or-number decision would be lost. While reading, it notes keys that appear twice in one object (the last value wins, as with JSON.parse) and whole numbers too large for JavaScript to hold exactly, and both show up as notes above the schema.
Every value is then filed under its position, such as $.customer.email or $.items[*].sku. For each position the tool counts how often it saw strings, integers, numbers, booleans, objects, arrays and nulls, and for strings whether every value so far passed each format check and how many different values there were. Objects keep a count of how many times each key appeared, and arrays pour all of their elements into one item position.
The schema is written from those counts. One kind of value gives a single type, plus null when nulls were seen; integers mixed with decimals become number; several kinds give anyOf in the fixed order string, number or integer, boolean, object, array, then null. A key goes into required when its count equals the number of objects seen at that place. Properties keep the order in which they first appeared.
Changing an option after generating reuses the samples already read, so the schema updates as you tick boxes without parsing the text again. Editing the text clears the result until you press Generate schema.
Common use cases
- Turning a handful of real API responses into the schema for a model's structured output, so replies come back in the same shape as the live data
- Writing the parameters of a tool from example calls you would like the model to make
- Drafting a validation schema for a webhook payload before the provider publishes one
- Documenting the fields of an internal export that nobody wrote down, including which ones are sometimes missing
- Checking whether a field really is always present before marking it required in an API contract
How to use this tool
- Paste at least two records, with a line holding only --- between them, or open a .json file. Use sample orders loads three made-up shop orders.
- If your file is one big array, tick Treat a top-level array as a list of samples so the schema describes one record instead of the array.
- Press Generate schema and read the line above the result: how many samples were used, how many properties were found and how many were missing from some objects.
- Read the amber notes. A field that was always null or an array that was always empty needs a type filled in by you.
- Pick the output: plain schema, response_format object or tool definition. For the wrappers, type a name, and for a tool a description.
- Turn on Strict mode if the target API asks for every field to be required with no extra properties, then copy the result or download it as .json.
Example
Two support-ticket records from a webhook log
{"ticket": 88121, "opened": "2026-04-07T08:02:44Z",
"assignee": "dana@example.com", "minutes": 42.5,
"labels": ["billing"]}
---
{"ticket": 88122, "opened": "2026-04-07T08:10:03Z",
"assignee": null, "minutes": 7}Generated schema (formats on, strict mode off)
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"ticket": { "type": "integer" },
"opened": { "type": "string", "format": "date-time" },
"assignee": { "type": ["string", "null"], "format": "email" },
"minutes": { "type": "number" },
"labels": { "type": "array", "items": { "type": "string" } }
},
"required": ["ticket", "opened", "assignee", "minutes"]
}
(minutes is number because 42.5 has a decimal point; labels is
missing from ticket 88122, so it is not required. With strict
mode on, labels becomes ["array", "null"], all five keys are
required and additionalProperties is false.)Tips for best results
- Feed it variety, not volume. Five records that include an empty array, a missing optional field and a null teach it more than five hundred records that all look alike.
- If one record is an outlier, such as a test entry with every field empty, leave it out; one null is enough to make a field nullable.
- Keep Detect formats on for API data but read the result: a date field that was always filled with real dates gets format date, and one blank string in it removes the format.
- Turn enums on only when the samples cover every allowed value. An enum learned from three statuses will reject the fourth one the first time it appears.
- Run the schema through the JSON Schema Validator on this site with a few fresh records that were not used as samples. Any failure points at a guess the generator could not have made from the samples alone.
- After generating, add the rules no sample can reveal: minimum and maximum values, string patterns, maxLength, and descriptions that tell a model what each field means.
Edge cases to watch
The schema can only be as broad as the samples. A field that happens to be present in every sample is marked required even if the real system sometimes leaves it out.
A value written as 10.0 is typed number even if the field only ever holds whole amounts. If you want integer, edit the type or change the sample.
Strings are never given a pattern, length limit or numeric range. Codes such as "0042" stay plain strings.
Arrays are treated as lists of similar items. A fixed-position pair such as [longitude, latitude] becomes an array of numbers, not a two-item tuple.
A field that was null in every sample is typed as null only, which would reject every real value later.
Common errors and how to fix them
- "The sample is not valid JSON: line 2, column 1" with a note about putting --- between records
- Two JSON values follow each other with no separator, which is what a JSON Lines file looks like. Put a line holding only --- between the records, or wrap them in [ ] with commas between and tick the top-level array option.
- "Sample 2 of 3 is not valid JSON" pointing at a closing brace
- The line number counts from the top of the whole box, so jump to it directly. A comma before } or ], a single-quoted string or a comment are the usual causes; the lines under the heading say what the parser found at that spot.
- "The top-level array is empty, so there is nothing to learn a schema from."
- The file is [] and the top-level array option is on. Load a file that contains records, or turn the option off to describe the empty array itself.
- A note says a field was null in every sample
- The generator has no value to learn from. Add a sample where the field is filled in, or change its type by hand after copying the schema.
- The file is refused as a ZIP archive or Office file
- A workbook or a zipped export was picked instead of the JSON inside it. Extract or export the .json file and open that.
- The size line turns red above 2 MB
- Trim the input to a few hundred records that cover every variation. The schema depends on the variety of the records, not on how many there are.
Best practices
- Treat the generated schema as a first draft and read every required list before using it.
- Keep the sample file next to the schema, so the schema can be regenerated after the data changes.
- Add a description to each property before sending the schema to a model; the generator cannot know what a field means.
- Send null rather than leaving a field out when you produce data for a strict schema.
How required and optional are decided
For every object position the generator counts how many objects it saw there and how many of them carried each key. A key is required only when the two counts match. That rule applies at every level: for the line items inside an order, a key is required only if every line item in every order had it, so one gift_wrap flag on one item leaves gift_wrap optional.
A key that is present but null still counts as present. In the example above, assignee is required because both tickets carry it, and nullable because one of them holds null. Being absent and being null are different things in JSON Schema, and the output keeps them apart.
What strict mode changes
Strict mode writes the shape that strict structured-output features usually ask for: every property listed in required and additionalProperties set to false on every object, including objects inside arrays and inside anyOf. Because a required field can no longer be left out, each optional field gets null added to its type instead, so ["string", "null"] replaces a plain string, and an enum on such a field gains null as an allowed value.
The page lists the fields it made nullable. Anything that produces data for the schema must then send "labels": null where it used to omit labels, which is easy to forget in code that builds objects field by field.
When formats and enums are added
A format is written only when every string seen at that position passes the check. date-time needs seconds and a zone, as in 2026-04-07T08:02:44Z, so a value like 2026-04-07 08:02:44 keeps the field a plain string. date needs a real calendar date, so 2026-02-30 disqualifies the field. email and uri are added only for plain name@domain.tld addresses and for values with a scheme and a host, such as https://example.com/a; codes such as user:42 or urn:isbn values pass the uri rule of the standard but are left as strings here. uuid accepts any version in upper or lower case. The checks are the same functions the validator on this site uses, so a format the generator writes will not fail there on the samples that produced it.
With enums turned on, a string field gets an enum when it was seen at least 5 times, had no more than 10 different values, none longer than 60 characters, and each value appeared at least twice on average. A field that also matched a format is left without an enum.
Limits worth knowing
Repeated shapes are written out in full each time; the generator does not create $defs or $ref. Samples nested more than 128 levels deep are refused. Property names that are whole numbers, such as "2024", are listed first inside properties because JavaScript objects always order such keys first, although required keeps their original order.
Everything happens in the open tab: a chosen file is read with the browser's file API, and the schema is built by the page's own script. Nothing you paste is uploaded, and this tool writes nothing to localStorage, sessionStorage or IndexedDB.
Frequently asked questions
Why is a field typed number when every value is a whole number?
At least one sample wrote it with a decimal point or an exponent, such as 18.0 or 1e2. The generator goes by how the value is written, so change the sample or edit the type if the field should be integer.
How many samples do I need?
Enough to show every variation: a record with each optional field missing, one with each nullable field null, and one with every array non-empty. Two or three well-chosen records often do; fifty similar ones add nothing.
Can I paste JSON Lines?
Not directly, since one line after another is not valid JSON as a whole. Put a --- line between records, or wrap them in [ ] with commas between and tick the top-level array option.
Does the schema include descriptions or examples?
No. It describes structure only. Add a description to each property by hand, especially when a model will read the schema to decide what to put in each field.