How to use the json schema generator
- Paste a JSON sample into the first box, or edit the example. The text is checked as you type, and a mistake is shown with its line and column.
- Choose the schema version: draft 2020-12 or draft 7. The version sets the address written in the "$schema" line.
- Choose which keys are required: all of them, only the keys found in every object, or none. Optionally disallow extra keys and add formats for dates, emails, web addresses and UUIDs.
- Copy the schema or download it as schema.json, then review it against your real data.
What the generator writes
For each value in the sample it writes a type: string, integer, number, boolean, null, array or object. Nested objects become nested "properties" with a "required" list, and arrays get an "items" schema that merges every item. If the items are objects with different keys, the merged schema lists every key, and the "keys in every object" option marks only the keys that all of them had.
A number written without a decimal point is an integer, and one written with a decimal point or an exponent, such as 1.0, is a number. If the same place holds a string in one object and a number in another, the type becomes a list, such as ["integer", "string"]. An empty array has no "items" because nothing in it shows what it holds.
Why the result is a starting point
A schema made from one sample describes that sample, not every document your system will meet. A key that is always present here may sometimes be missing, a number that is always whole may sometimes have decimals, and a string with a date in it may be free text in other documents. Add more samples by pasting an array of them: the tool merges them into one schema.
Format detection is a guess from the look of the text, so it is off by default. When on, a format is written only if every string in that place matches the same one. Use the JSON formatter and validator to check the sample first, the JSON viewer to browse it, and the JSON to TypeScript tool to get types for code.
Privacy and limits
Everything runs in your browser and nothing is uploaded. The text is parsed with the browser's JSON parser and a strict reader that gives clear positions for errors, and it is never run as code. Samples up to 2,000,000 characters are accepted, and very deep nesting is stopped before it can hang the page.
Assumptions and limits
- The schema is inferred from the sample you paste. It does not know your rules for ranges, patterns or allowed values.
- Draft 2020-12 and draft 7 use different addresses in the "$schema" line. The other keywords written here are the same in both.
- Format detection looks at the text only and may be wrong.
- Duplicate keys in one object are treated as one key.
Frequently asked questions
How do I generate a JSON schema from JSON?
Paste a sample of the JSON into the box. The tool reads each value, writes its type, and builds properties, required lists and array items for you.
What is the difference between draft 7 and 2020-12?
They are versions of the JSON Schema specification. This tool writes the same basic keywords for both and changes only the address in the "$schema" line, so check which version your validator expects.
How are optional keys decided?
With "Keys in every object", a key is required only if every object in the sample had it. Choose all or none to override that.
Why is a number shown as an integer?
A value written without a decimal point, like 36, is an integer. Write 36.0 or sample some decimals if the field can have them.
Is my JSON sent anywhere?
No. The sample is processed in your browser tab and is not uploaded or stored.