JSON to JSON Schema Generator
Paste JSON, get a JSON Schema document — Draft 2020-12, 7, or 4 — configure required fields and additionalProperties
Options
243 characters
Draft 2020-12 · 950 characters
You have a JSON object — an API response, a configuration file, a database record — and you need a JSON Schema that describes its structure. Instead of writing the schema by hand (which means spelling out every field name, every type, every nested object), this tool infers the schema automatically from your data and generates valid JSON Schema for Draft 2020-12, Draft 7, or Draft 4.
What Is JSON Schema?
JSON Schema is a vocabulary for describing the structure of JSON data. It is itself a JSON document that specifies what fields are allowed, what types they must be, which fields are required, and how nested structures are shaped.
A JSON Schema serves multiple purposes simultaneously:
- Validation — check that incoming data matches the expected shape before processing it
- Documentation — describe an API’s request and response shapes in a machine-readable format
- Code generation — tools like
quicktype,json-schema-to-typescript, anddatamodel-code-generatorcan generate typed code from a JSON Schema - Form generation — UI libraries like
react-jsonschema-formrender HTML forms directly from a JSON Schema - Editor support — JSON Schema files registered with VS Code or JetBrains IDEs provide autocomplete and validation in JSON files
Schema Draft Versions
JSON Schema has evolved through several draft versions. This tool supports the three most commonly used:
Draft 2020-12
The current stable specification (published December 2020). Use this for new projects.
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"name": { "type": "string" }
}
}
Notable features: prefixItems for tuple validation, $dynamicRef for recursive schemas, improved unevaluatedProperties.
Draft 7
The most widely supported draft. Most validators, code generators, and API tools support Draft 7. Use this when targeting broad tool compatibility.
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"name": { "type": "string" }
}
}
Notable features: if/then/else, readOnly/writeOnly, $comment.
Draft 4
An older draft still required by some tools, including Swagger/OpenAPI 2.0, which uses a JSON Schema Draft 4 subset. Use this only when a specific tool requires it.
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"name": { "type": "string" }
}
}
Required Fields
The required keyword specifies which fields must be present for the data to be valid. This tool offers three modes:
All fields (default): Every key in the JSON object is listed in required. This is the strictest mode — it means the schema will reject any object missing even one of the fields from your sample data.
None: No required array is generated. Every field becomes optional. Use this when the JSON you pasted is a maximal example but some fields may be absent in practice.
Non-null only: Fields whose value is null in your sample are excluded from required. Everything else is required. This is a good default if you use null to represent absent values.
additionalProperties
When additionalProperties is false (the default), the schema will reject any object that contains keys not listed in properties. This is a strict validation mode useful for API request validation where unknown fields should be rejected.
When additionalProperties is true, objects may contain any additional keys beyond those listed in properties. Use this when your sample JSON is a representative subset and the real data may include more fields.
Type Mapping
| JSON value | JSON Schema type |
|---|---|
"hello" | {"type": "string"} |
42 | {"type": "integer"} |
3.14 | {"type": "number"} |
true / false | {"type": "boolean"} |
{...} | {"type": "object", "properties": {...}} |
[...] | {"type": "array", "items": {...}} |
null | {} (empty schema, matches anything) |
Note: JSON Schema does not have a dedicated null type keyword (though "type": "null" is valid). An empty schema {} is used here because it matches any value, which is the correct representation when the actual type is unknown from a single null example. If you know the field should allow only null, or should be a specific type that happens to be null in this sample, adjust the schema manually after generating.
Tools That Consume JSON Schema
Once you have a JSON Schema, many tools can work with it:
Validation libraries:
- JavaScript:
ajv(fastest),joi,zod(withzod-from-json-schema) - Python:
jsonschema,fastjsonschema - Java:
json-schema-validator - Go:
gojsonschema
Code generators:
json-schema-to-typescript— generates TypeScript interfaces from Draft 7/2020-12datamodel-code-generator— generates Pydantic, dataclasses, or attrs from JSON Schemaquicktype— supports multiple target languages
API tools:
- OpenAPI / Swagger uses JSON Schema (Draft 4 subset) for request/response schemas
- AsyncAPI uses JSON Schema for message payload schemas
- Postman and Insomnia support JSON Schema for response validation
Form generation:
react-jsonschema-form— renders HTML forms from JSON Schema@rjsf/mui— Material UI variant of the abovejsonforms— cross-framework form generation
How to Use This Tool
- Paste your JSON in the JSON Input panel (or click Load sample)
- Select the Draft version your target tool requires
- Optionally add a Title and Description for the root schema
- Set the Required mode to match how strict your validation should be
- Toggle additionalProperties based on whether you want to reject unknown fields
- Copy the output or Download .json to save it
Handling Nested Objects
Nested JSON objects are recursively expanded into nested $schema objects with their own properties, required, and additionalProperties based on your options:
{
"address": {
"type": "object",
"properties": {
"street": { "type": "string" },
"city": { "type": "string" }
},
"required": ["street", "city"],
"additionalProperties": false
}
}
Handling Arrays
Arrays are represented with an items schema inferred from the array contents. If the array contains objects, all objects are merged to capture the union of all keys:
{
"tags": {
"type": "array",
"items": { "type": "string" }
},
"posts": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": { "type": "integer" },
"title": { "type": "string" }
}
}
}
}
FAQ
Does this tool send my JSON to a server?
No. All processing runs entirely in your browser. Your data never leaves your device.
What is the difference between JSON Schema and JSON?
JSON is a data format. JSON Schema is a schema language for describing and validating JSON data. A JSON Schema document is itself valid JSON, but it describes the structure of other JSON documents rather than being application data itself.
Can I use the generated schema with OpenAPI?
Yes, with caveats. OpenAPI 2.0 uses a Draft 4 subset — select Draft 4 and remove unsupported keywords. OpenAPI 3.0 uses a Draft 7 subset. OpenAPI 3.1 is fully aligned with Draft 2020-12 — select Draft 2020-12 for OpenAPI 3.1 compatibility.
How do I add an enum constraint to a string field?
After generating, manually replace {"type": "string"} with {"type": "string", "enum": ["active", "inactive"]} for the field in question. This tool generates structural schemas from data instances; value constraints must be added manually.
What if my JSON has fields that can be multiple types?
The tool infers the type from the single value present in your sample. For true union types, manually edit the generated schema to use anyOf: {"anyOf": [{"type": "string"}, {"type": "integer"}]}.
How do I validate JSON against the generated schema in JavaScript?
Install ajv and use it as follows:
import Ajv from "ajv";
const ajv = new Ajv();
const validate = ajv.compile(schema); // your generated schema
const valid = validate(data);
if (!valid) console.error(validate.errors);