JSON Schema Generator
Generate a JSON Schema from sample JSON data, with types, nested objects, arrays and required properties worked out for you, ready to copy or download. Runs in your browser.
Input
Output
Readme
What does the JSON Schema Generator do?
It writes a JSON Schema for you from an example of your data. Paste a sample, such as an API response, a configuration file or a record from a database export, and you get a schema that describes its structure: the type of every value, the properties of every object, what the items of every array look like, and which properties are required. It's a quick start for API documentation, OpenAPI specs, form validation or data contracts, which you can then tighten by hand.
How to use it
- Paste or type sample JSON in the input box.
- Pick the JSON Schema draft for the
$schemaline: Draft 2020-12 or Draft 7. - Choose whether properties should be marked as required.
- Copy the schema or download it as
schema.json.
If the sample isn't valid JSON, the tool gives the line and column of the problem and marks it.
How the schema is worked out
- Every value gets its JSON type:
string,boolean,null,object,array, andintegerfor whole numbers ornumberfor numbers with decimals. An array of whole and decimal numbers getsnumber, which covers both. - Objects get a
propertiesentry for each key, described the same way, as deep as the sample goes. - Arrays get one
itemsschema that fits every item. When the items are objects, their properties are merged, so a list of records gives one schema for a record. - Values of mixed types get every type in a list, such as
["string", "null"], or ananyOfwhen objects and other values are mixed. - An empty array gets
"type": "array"with noitems, since there is nothing to describe.
Required properties
With "Mark properties as required" on, each object lists its keys under required. For an array of objects, a property is required only when every item has it: in a list of members where only some have a favorite, that property is optional. Turn the option off to get a schema without any required lists.
What a sample can't tell
A schema made from one example only knows what the example shows. It can't know which string values are emails or dates, the ranges numbers may take, or that a property seen once may also be missing. Add format, minimum, maxLength, enum or pattern by hand where you need them, and check data against the result with the JSON Schema Validator.
How it works
The tool uses genson-js, a JavaScript port of the GenSON schema builder. The keywords it writes mean the same in Draft 7 and Draft 2020-12, so the draft only changes the $schema line. Everything runs in your browser: the sample is never uploaded.
Features
- JSON Schema from any sample JSON
- Types, nested objects and arrays worked out for you
- Array items merged into one schema, with optional properties found
- Draft 2020-12 or Draft 7
- Required properties on or off
- Copy or download as
schema.json - Runs in your browser