Developer Tools
JSON to Mongoose Schema Converter
Generate a Mongoose schema and model from any JSON document in your browser. Detects ObjectId, Date, subdocuments, and arrays of samples.
Schema naming
Module syntax
Indent
Schema behavior
Nested objects become
Choose Schema to promote every nested object to a reusable subdocument schema. Inline keeps the shape next to the field.
Mark fields as required
Fields seen as null in any sample stay optional regardless. With an array of samples, only fields present in every sample qualify.
How JSON values map to Mongoose types
"hello"
String
Plain string
"507f1f77bcf86cd799439011"
Schema.Types.ObjectId
24-hex string with detect on
"2026-01-15T09:00:00Z"
Date
ISO 8601 string with detect on
42
Number
Integer or float
true
Boolean
Boolean
null
Schema.Types.Mixed
Pure null falls back to Mixed
[]
[Schema.Types.Mixed]
Empty array has no element info
[1, 2, 3]
[Number]
Homogeneous array
[{ "x": 1 }, { "x": 2 }]
[XSchema] or inline [{ x: Number }]
Array of objects becomes subdocs
How to use
- Paste a JSON document into the input area, or click Load document sample for a worked example. An array of similar documents also works.
- Set the Schema name (default User). Optionally set a model export identifier and a collection name to override Mongoose's default pluralization.
- Pick ES modules or CommonJS to match your project, then choose 2 or 4 space indent.
- Pick how nested objects are emitted: their own Schema, inline shape, or Schema.Types.Mixed. Use Schema for reusable subdocuments.
- Pick the required mode (all present fields, top level only, or never), toggle timestamps, _id on subdocuments, strict, versionKey, and Date or ObjectId detection.
- Click Copy schema to grab the generated Mongoose code, paste it into your project, and adjust validators or indexes as you go.
About this tool
JSON to Mongoose Schema Converter takes a sample JSON document (or an array of documents) and emits a Mongoose schema and model that match its shape. The inferrer walks the parsed value and maps strings, numbers, booleans, and nested structures to their Mongoose equivalents: String, Number, Boolean, Date for ISO 8601 strings, Schema.Types.ObjectId for 24-character lowercase hex strings, Schema.Types.Mixed when types conflict across samples, and arrays of typed elements or promoted subdocument schemas for arrays of objects. When the root is an array, every element is merged so a key present in some samples becomes non-required and a value type that varies across samples falls back to Mixed; this is how you should hand a sample-set to the converter when you want a schema that accepts every document you have on hand. Nested objects can be promoted into their own named Schema instances (the Mongoose idiom for reusable subdocuments), kept inline next to the parent field, or collapsed into Schema.Types.Mixed when you want flexibility over validation. Naming options cover the schema identifier (which becomes the model name in the registry and the camelCase const for the schema), an optional model export identifier, and an optional collection name override. Module syntax switches between ES modules with import and CommonJS with require to match an existing project. Schema-level options include timestamps for createdAt and updatedAt, versionKey: false to drop __v, strict: false for permissive documents, and _id: false on subdocuments so embedded value objects do not get their own ObjectId. The required heuristic has three modes: every field that is present in every sample, only top-level fields, or never; fields seen as null in any sample always stay optional regardless of the mode. Indent toggles between 2 and 4 spaces. Useful when scaffolding a model from a third-party webhook payload, a Postman response, an existing MongoDB document export, a fixture file, or a record sample from a colleague; or when you want a starting schema for a new collection and have a sketch of the JSON document you plan to store. Parsing, inference, and code generation all run locally in your browser, so the JSON payloads, collection names, and field names you put in here never leave your device.
Free to use. Works in your browser. No signup, no login.
Related tools
You may also like
JSON to TypeScript Converter
Generate TypeScript interfaces or types from any JSON value with full inference.
Open tool
DeveloperJSON to Zod Schema Converter
Infer a Zod schema and TypeScript type from any JSON sample.
Open tool
DeveloperJSON Schema Generator
Infer a JSON Schema document (Draft 7 or 2020-12) from any JSON value.
Open tool
DeveloperMongoDB ObjectId Decoder
Decode MongoDB ObjectIds to a date, hex bytes, and per-field breakdown.
Open tool
DeveloperJSON Formatter
Format, minify, and validate JSON in your browser.
Open tool
DeveloperJSON to Python Converter
Generate a Python dict, dataclasses, or Pydantic models from any JSON value.
Open tool