JSON Schema Builder

Generate a JSON Schema or MongoDB $jsonSchema from a form, with live validation

Properties

Test document

VALID

The document matches the generated MongoDB schema.

Generated schema

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "email": {
      "type": "string",
      "description": "User email address",
      "pattern": "^[^@]+@[^@]+\\.[^@]+$"
    },
    "age": {
      "type": "integer",
      "description": "Age in years",
      "minimum": 0,
      "maximum": 150
    },
    "role": {
      "type": "string",
      "enum": [
        "admin",
        "editor",
        "viewer"
      ]
    }
  },
  "required": [
    "email",
    "age"
  ]
}

Examples

A user document schema

Input
email (string, required, pattern), age (integer, required, 0–150), role (enum)
Output
A draft-07 JSON Schema and the matching MongoDB $jsonSchema with required fields and constraints.

The form starts with a sensible example — adjust it and both schema formats update live.

Validate before you deploy

Input
{ "email": "ada@example.com", "age": 36, "role": "editor" }
Output
VALID — the test document matches the generated $jsonSchema.

The Test tab validates a sample document against the generated schema so you catch mistakes before applying it to a collection.

About this tool

A schema is the cheapest way to stop bad documents reaching your store, but writing JSON Schema or MongoDB's $jsonSchema by hand is fiddly — one wrong keyword silently lets invalid data through.

This builder turns a form into a correct schema: add properties, pick a type, mark which are required, and add constraints such as string patterns, numeric minimum/maximum, and enum lists. It emits both a standard draft-07 JSON Schema and the equivalent MongoDB $jsonSchema validator, and you can validate a test document against the generated schema live before you deploy it.

How to use

  1. Add properties

    Click Add property, name the field, pick its type, and tick required where needed.

  2. Add constraints

    Set a pattern for strings, minimum/maximum for numbers, or an enum list for any type.

  3. Copy the output

    Use the JSON Schema or MongoDB $jsonSchema tab and copy the generated schema.

  4. Test a document

    Paste a sample document on the left to confirm the schema accepts what you expect and rejects what it shouldn't.

Common mistakes

Mistake:Listing a property but forgetting to mark it required.

Fix:Tick the 'required' checkbox — properties are optional unless you add them to the required list.

Mistake:Using the wrong bsonType for MongoDB.

Fix:The builder maps each type to the correct bsonType alias (e.g. integer → int, boolean → bool) automatically.

Frequently asked questions

References & standards