JSON Schema Generator
Build a draft-07 schema from a sample JSON object.
-
1Enter data
Enter content, paste text or load a file from disk. -
2Click the button
The tool will immediately process your data in the browser. -
3Get the result
Copy the finished text or save the file to your device.
return "Result ready in 0.1s";
}
Rate this tool:
Related tools
Other tools you may find usefulJSON Schema generator - a draft-07 schema from sample JSON
The JSON Schema generator turns a sample JSON object into a ready draft-07 schema. You paste a representative slice of your data and the tool infers the type of every field, builds the properties section and the required list, and describes array elements through items. You get a starting point for validating API responses, configuration files and forms.
What JSON Schema is
JSON Schema is a language for describing the structure of JSON data, written in JSON itself. Instead of noting in a comment that id is an integer and tags is an array of strings, you state it formally and let a validator check conformance. A schema plays three roles at once: a contract, documentation a person can read, and a rule a machine can run. The keywords - type, properties, required, items, $schema - mean the same in any language.
How inference from a sample works
The tool parses the pasted JSON and walks its structure recursively. For an object it builds a properties section describing each field, and adds fields with a non-empty value to required. For an array it sets the element type through items, based on the first element. Simple values map onto JSON Schema types: a whole number becomes integer, a decimal becomes number, a logical value becomes boolean, null yields null, and text becomes string. Since that split comes from how the value is written, put a decimal point in the example for fields that are sometimes fractional.
type, properties, required, items - what the result contains
| Keyword | Role in the schema | Where the generator gets it |
|---|---|---|
$schema | points at the specification version | written in at the top by default |
type | the value type: object, array, string, integer, number, boolean, null | from the value in the sample |
properties | a description of the object fields | from the keys of the JSON object |
required | the fields that must be present | from fields with a non-empty value |
items | the array element type | from the first element of the array |
Nested objects and arrays
Nested structures are handled fully recursively: an object inside an object gets its own properties section, and an array of objects describes in items the schema of a single record with its required list. An empty object {} becomes type: object with empty properties, and an empty array [] becomes type: array with no items key, because the element type cannot be guessed from an empty array. Rather than write a made-up type, the tool leaves a slot for you to fill in.
How to generate a schema step by step
- Paste a representative sample - the fuller the object, the more accurate the schema.
- Click Generate schema. The result appears on the right, formatted with indentation.
- Check the required list and remove the fields that are actually optional.
- Add what a single sample cannot show:
format,pattern,enum, numeric bounds. - Copy the finished schema and load it into a validator.
Draft versions and the $schema field
The $schema field declares which version of the specification the schema is read against. The generator writes the draft-07 address, widely supported by validators in PHP, JavaScript and Python. Newer releases (2019-09, 2020-12) changed how array elements are described: the array form of items became prefixItems. If your validator needs a newer version, swap the address and adjust the changed fragments.
Validating data against the schema
The schema on its own checks nothing - you need a validator that compares data against it: justinrainbow/json-schema in PHP, Ajv in JavaScript, jsonschema in Python. It reports mismatches: a missing required field, a wrong type, a value outside enum. To first check that the JSON is syntactically correct, use the JSON validator, and to explore the structure as a tree, the online JSON viewer.
What JSON Schema is used for in practice
The most common use is API input validation: the server rejects data that does not match the schema. A schema is also API documentation, describes form rules consistently on client and server, and in configuration files hints at allowed keys and types. Before it lands in a repository, tidy its layout with the JSON formatter.
required; a whole number gets integer even though it is sometimes fractional. Treat the result as a draft and finish it by hand, especially the required list.Frequently asked questions
What is draft-07?
It is one of the versions of the JSON Schema specification, widely supported by validators and tools. The generator writes the address of this version in the $schema field. Newer releases (2019-09, 2020-12) introduced prefixItems instead of the array form of items.
Does the schema enforce fields right away?
No. The generator only proposes a required list based on the fields with a non-empty value in the sample. You decide which fields are truly mandatory.
What happens when I paste invalid JSON?
The tool will not return a broken result - an error message describes the problem. If valid JSON is a bare simple value, such as a number or a string, you get a message that the root element must be an object or an array.
How are nested objects and arrays handled?
Fully recursively. An object inside an object gets its own properties section, and an array of objects describes in items the schema of a single element with its required list. The array element type comes from the first element.
How do I validate data using the schema?
Load the schema into a validator: justinrainbow/json-schema in PHP, Ajv in JavaScript, jsonschema in Python. It points out mismatches - a missing required field, a wrong type, or a value outside the allowed set.