DevTools Logo

JSON Schema Builder

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.

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 this tool

  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

What is the difference between the JSON Schema and the $jsonSchema output?

The JSON Schema tab emits a standard draft-07 schema; the MongoDB tab wraps the equivalent validator in { "$jsonSchema": { ... } } and maps types to bsonType aliases (e.g. integer → int, boolean → bool) for db.runCommand({ collMod }).

Does the Test tab use the same rules as the NoSQL Validator?

Yes — the test document is validated against the generated schema with the same engine, so what you see here matches the standalone validator.

Is my schema or sample data uploaded?

No. The builder and validator run entirely in your browser. Nothing leaves this tab.

References & standards