Auto-generate JSON Schema from JSON data with type inference
Features
- Intelligent Type Inference: Automatically detect data types from JSON values, including strings, numbers, booleans, arrays, objects, and null, with smart format detection for email, URL, date, and time
- Multi-Version Support: Support JSON Schema Draft 2020-12, 2019-09, Draft-07, and Draft-04 with proper $schema URIs and version-specific features
- Validation Rules: Configure required fields, type constraints, format validation, and strict mode with additionalProperties control for robust schema definition
- Flexible Configuration: Include or exclude field descriptions, examples, and strict validation rules based on your API documentation and validation needs
Usage Guide
- Input JSON Data: Paste your sample JSON data or load the example to get started
- Configure Options: Select Schema version, enable required fields, descriptions, and other options
- Generate Schema: Click generate to create JSON Schema with automatic type inference
- Use Schema: Copy or download the generated schema for API validation or documentation
Technical Details
JSON Schema Specification
JSON Schema is a declarative language for describing the structure and validation rules of JSON data. It uses keywords like 'type', 'properties', 'required', 'items', and 'additionalProperties' to define constraints. The specification has evolved through multiple drafts, with Draft 2020-12 being the latest stable version. Schemas are themselves valid JSON documents that can be used for validation, documentation, and code generation.
Type Inference Algorithm
The generator analyzes JSON values to infer appropriate schema types. For primitives, it detects string, number, integer, boolean, or null. For strings, it applies format detection using regex patterns to identify email, uri, date, time, ipv4, ipv6, and other standard formats. For objects, it recursively generates nested schemas with property definitions. For arrays, it infers the schema from the first element.
Validation Keywords
JSON Schema provides rich validation keywords: 'type' for data type, 'required' for mandatory fields, 'properties' for object schemas, 'items' for arrays, 'minimum'/'maximum' for numbers, 'minLength'/'maxLength' for strings, 'pattern' for regex validation, 'enum' for allowed values, and 'format' for semantic validation like email or URL. These keywords combine to create comprehensive validation rules.
Frequently Asked Questions
- What is JSON Schema and why use it?
- JSON Schema is a vocabulary for annotating and validating JSON documents. It describes data structure, constraints, and validation rules using JSON format itself. Benefits include: automatic data validation, API documentation, code generation, improved developer experience, and contract-based development. It's widely used in API design, configuration validation, and form generation.
- Can this tool generate schema from any JSON?
- Yes! This tool analyzes any valid JSON input and generates corresponding JSON Schema Draft-07 compatible schema. It handles all JSON data types: objects, arrays, strings, numbers, booleans, and null. It infers types, required fields, and basic patterns from your sample data. For complex scenarios, you may need to manually refine the generated schema.
- How accurate is the generated schema?
- The generator creates schemas based on sample data analysis. It accurately identifies data types and structures but makes conservative assumptions about constraints. For example, it won't know if a number should be positive-only or if a string must match a specific pattern unless those constraints appear in all samples. Always review and enhance generated schemas with your domain-specific validation rules.
- Can I use the generated schema for validation?
- Absolutely! The generated schema is fully compatible with JSON Schema validators like Ajv, joi, or json-schema library. You can use it to validate API requests/responses, configuration files, or user inputs. The schema follows JSON Schema Draft-07 specification and can be integrated into Node.js, Python, Java, or any language with JSON Schema support.
- What's the difference between different JSON Schema drafts?
- JSON Schema has evolved through multiple drafts (Draft-04, Draft-06, Draft-07, 2019-09, 2020-12). This tool generates Draft-07 schemas which are widely supported. Key differences: Draft-07 added if/then/else conditionals, Draft 2019-09 introduced vocabulary system, Draft 2020-12 added unevaluatedProperties. For most uses, Draft-07 provides excellent compatibility and feature set.
Related Documentation
- JSON Schema Official Website - Official JSON Schema specification and documentation
- Understanding JSON Schema - Comprehensive guide to JSON Schema concepts and usage
- JSON Schema Draft 2020-12 - Latest JSON Schema specification document
- JSON Schema Validator - Online tool to validate JSON against schemas
- OpenAPI and JSON Schema - How JSON Schema is used in OpenAPI specification