{}?JSON Schema Generator
Loading...
JSON Schema is a standard for describing the structure and validation rules of JSON data. It is widely used for API documentation, input validation, and code generation. This tool analyzes your JSON data and automatically generates the corresponding schema.
How to Use
- 1Enter JSON
Paste your JSON data into the left input area. Click 'Load Example' to try a sample.
- 2Configure options
Choose the Draft version (2020-12, 2019-09, Draft 07), and toggle required fields, additionalProperties, and format detection (email, date, uri, etc.).
- 3Review and copy
The generated JSON Schema appears on the right. Copy it to clipboard or download it as a file.
Tips
- 💡When an array contains multiple objects, common keys are marked as required and keys present only in some objects become optional.
- 💡Enable format detection to automatically recognize email, date, date-time, uri, and uuid string formats.
- 💡Disabling additionalProperties allows fields not defined in the schema to pass validation.
- 💡The generated schema works directly with validation libraries like ajv, zod, and Pydantic.
FAQ
- Q. What is JSON Schema used for?
- A. JSON Schema defines the structure, data types, and validation rules for JSON data. It is used for API documentation (OpenAPI/Swagger), request body validation, code generation, and editor autocomplete support.
- Q. How do I use JSON Schema for validation in code?
- A. Use ajv in JavaScript/Node.js, jsonschema in Python, or json-schema-validator in Java. Validating API request bodies against a schema at the server boundary catches invalid data early and improves error messages.
- Q. What is the difference between required and nullable?
- A. required means the field must be present in the object. nullable (or type: ["string", null]) means the field can have a null value. A field that is not required but not nullable simply means it is optional — if present, it cannot be null.
- Q. How do JSON Schema draft versions differ?
- A. Newer drafts (2019-09, 2020-12) add features like $defs (replacing definitions), unevaluatedProperties, prefixItems for tuple validation, and improved reference handling. Check which draft version your chosen validation library supports.