JSON Schema
A comprehensive JSON Schema editor with tree-based interface, BSON type support, and validation rules for MongoDB collections. Create, edit, and verify schemas with full MongoDB BSON type compatibility.
Quick Start
Create your first JSON schema in three simple steps:
- Navigate to Tools > JSON Schema Manager from the top menu
- Click New Schema or Import from Database to analyze an existing collection
- Use the tree editor to define fields, set BSON types, and add validation rules
Schema Manager Overview
The JSON Schema Manager provides two main tabs for working with schemas:
Saved Schemas Tab
- Local Schema Library - View and manage all schemas saved in VisualLeaf's local storage
- Folder Organization - Organize schemas into folders and subfolders for better project management
- Search and Filter - Quickly find schemas by name with real-time search
- Sort Options - Sort by name (A-Z, Z-A), creation date, or modification date
- Drag and Drop - Move schemas between folders with drag and drop
- Import from Database - Analyze existing collections to automatically generate schemas
MongoDB Schemas Tab
- Database Selection - Select a connected database to view its validation schemas
- Collection Validators - View and edit JSON Schema validators that are configured directly on MongoDB collections
- Direct Deployment - Deploy schema validation rules directly to your MongoDB collections
Tree-Based Schema Editor
The tree editor provides an intuitive interface for building complex nested schemas:
Tree Structure Features
- Hierarchical View - Visualize nested objects and arrays in an expandable tree structure
- Drag to Reorder - Drag fields up and down to reorder them within the schema
- Expand/Collapse - Click the arrow icons to expand or collapse nested structures
- Visual Indicators - Color-coded icons show field types at a glance (objects, arrays, strings, numbers, etc.)
- Required Fields - Mark fields as required with a checkbox
- Field Path Display - See the full path to each field (e.g., user.address.city)
Editing Fields
- Add Field - Click the + button to add a new field at any level
- Add Child - For objects and arrays, add nested fields by clicking the add child button
- Edit Field Name - Click the field name to edit it inline
- Delete Field - Click the trash icon to remove a field and all its children
- Duplicate Field - Copy a field and its entire nested structure
View Modes
- View Mode - Read-only view showing the complete schema structure
- Edit Mode - Full editing capabilities with all controls visible
- Quick Toggle - Switch between view and edit modes with a single click
BSON Type Support
Full support for all MongoDB BSON types with type-specific configuration:
Supported BSON Types
| Type |
Description |
string |
Text data (supports minLength, maxLength, pattern validation) |
number |
Generic number (int, long, double) |
int |
32-bit integer (supports min, max validation) |
long |
64-bit integer for large numbers |
double |
64-bit floating point number |
decimal |
128-bit decimal (Decimal128) for precise decimal arithmetic |
bool |
Boolean (true/false) |
object |
Embedded document with nested fields |
array |
Array of values (supports minItems, maxItems validation) |
date |
Date and time (BSON Date type) |
objectId |
MongoDB ObjectId (12-byte identifier) |
binData |
Binary data (files, images, etc.) |
null |
Null value |
regex |
Regular expression pattern |
timestamp |
MongoDB internal timestamp |
Multiple Type Support
A field can support multiple types (e.g., string or null, number or string). Select multiple checkboxes in the type selector to allow polymorphic fields.
Validation Rules
Define comprehensive validation rules for your schema fields:
String Validation
- minLength - Minimum string length (number of characters)
- maxLength - Maximum string length
- pattern - Regular expression pattern for format validation (e.g., email, phone number)
- enum - List of allowed values (dropdown selection)
- description - Human-readable description of the field's purpose
Number Validation
- minimum - Minimum numeric value
- maximum - Maximum numeric value
- multipleOf - Value must be a multiple of this number
- exclusiveMinimum - Value must be strictly greater than this
- exclusiveMaximum - Value must be strictly less than this
Array Validation
- minItems - Minimum number of items in array
- maxItems - Maximum number of items in array
- uniqueItems - All items must be unique (boolean)
- items - Schema for array elements (define structure for each item)
Object Validation
- required - List of required field names within the object
- properties - Schema definitions for each property
- additionalProperties - Allow or disallow fields not defined in the schema
Schema Verification Against Collection
Verify your schema against actual data in a MongoDB collection:
Verification Process
- Select Target - Click the "Verify Against Database" button and choose a connection, database, and collection
- Run Validation - VisualLeaf queries the collection using MongoDB's $jsonSchema operator to find non-matching documents
- View Results - A new Collection Activity tab opens showing all documents that fail to match the schema
- Identify Issues - Review non-matching documents to identify data quality problems or schema definition errors
- Fix and Retest - Update either the schema or the data, then run verification again
Use Cases
- Data Quality Audits - Find documents with missing required fields, wrong types, or invalid values
- Migration Planning - Identify documents that need to be updated before applying strict schema validation
- Schema Refinement - Discover edge cases in your data that your schema doesn't account for
- Validation Testing - Test your validation rules before deploying them to production
Import Schema from Database
Automatically generate schemas by analyzing existing MongoDB collections:
Import Process
- Select Collection - Click "Import from Database" and choose a connection, database, and collection
- Sample Analysis - VisualLeaf analyzes a sample of documents (default: 100) to infer the schema structure
- Type Detection - Automatically detects BSON types for each field based on the data
- Nested Structure - Preserves nested objects and arrays with their complete hierarchy
- Review and Edit - The imported schema opens in the editor for review and refinement
Import Options
- Save to Library - Save the imported schema to your local schema library for future use
- Deploy to MongoDB - Apply the schema as a collection validator directly to the database
- Merge Schemas - Import multiple collections and merge their schemas to understand relationships
JSON Schema Preview
View the generated JSON Schema in real-time as you build your schema:
Preview Features
- Real-Time Updates - The JSON preview updates automatically as you edit the schema (300ms debounce)
- Syntax Highlighting - JSON is displayed with color-coded syntax for better readability
- Formatted Output - JSON is pretty-printed with proper indentation
- Copy to Clipboard - Click the copy button to copy the complete JSON Schema to clipboard
- Resizable Panel - Drag the divider between editor and preview to adjust panel sizes
Export Options
- Download JSON - Export the schema as a .json file for use in other tools or version control
- MongoDB Format - The generated JSON is compatible with MongoDB's $jsonSchema validator
- Standard Compliance - Follows JSON Schema Draft 4 specification with BSON extensions
Folder Organization
Organize your schemas with a hierarchical folder structure:
Folder Operations
- Create Folder - Right-click on root or any folder and select "Create Folder" or "Create Subfolder"
- Rename Folder - Right-click a folder and select "Rename Folder" to change its name
- Delete Folder - Right-click and select "Delete Folder" to remove a folder and all its contents
- Move Schemas - Drag schemas between folders to reorganize your library
- Expand/Collapse - Click folder names to expand or collapse them
Keyboard Navigation
- Arrow Keys - Navigate up/down through folders and schemas
- Right Arrow - Expand a collapsed folder
- Left Arrow - Collapse an expanded folder or navigate to parent folder
- Enter - Open selected schema for editing or toggle folder expansion
Pro Tips
- Start with Import: Import an existing collection schema first, then refine it. This is much faster than building from scratch and ensures you don't miss any fields.
- Use Required Fields Wisely: Mark only truly essential fields as required. Over-constraining your schema can make it hard to evolve your data model over time.
- Test Before Deploying: Always use "Verify Against Database" to test your schema against real data before deploying it as a collection validator. This prevents breaking existing functionality.
- Organize by Project: Create top-level folders for each project or microservice, with subfolders for different environments (dev, staging, prod).
- Use Descriptions: Add descriptions to fields to document their purpose. This makes schemas self-documenting and helps team members understand the data model.
- Version Your Schemas: Export schemas to JSON files and commit them to version control (Git) to track changes over time and enable rollbacks if needed.
- VisuaSchema Designer - Create visual schema diagrams showing relationships between collections
- Collection Activity - View actual data in collections to understand the schema in context
- Aggregation Pipeline Builder - Use schema knowledge to build more accurate aggregation pipelines with proper field paths and type handling
- Index Management - Create indexes based on your schema definition to optimize query performance for frequently accessed fields