JSON to Mongoose Schema Converter
Paste a JSON document and get a ready-to-use Mongoose schema and model, with nested schemas, ObjectId refs and timestamps.
How to convert JSON to a Mongoose schema
- Paste a real document from your API or database into the left box. The sample shows every supported type.
- Type your model name, for example
UserorOrder. - Pick the options you want: required fields, trimmed strings, automatic
createdAt/updatedAttimestamps, or ES module syntax. - Copy the code or download it as
User.model.jsand drop it into yourmodelsfolder.
The converter runs in your browser. Your JSON is never sent to a server, so it is safe to paste real data.
How each JSON value becomes a Mongoose type
| JSON value | Mongoose type |
|---|---|
Text, such as "Aarav" |
String |
| Email text | String with lowercase: true |
24-character hex id, such as "65f1c2a9e4b0a1b2c3d4e5f6" |
Schema.Types.ObjectId with a ref guessed from the field name (managerId becomes ref: "Manager") |
ISO date text, such as "2026-01-15T10:30:00Z" |
Date |
| Any number | Number |
true or false |
Boolean |
| Nested object | Its own sub-schema with { _id: false } |
| Array of objects | An array of a sub-schema |
Empty, mixed or null values |
Schema.Types.Mixed |
Tips before you ship the schema
Paste more than one document. One sample can’t tell which fields are optional. Paste an array of a few documents and any field missing from some of them is left out of required.
Add the rules only you know. The converter can see types, not business rules. Add unique: true and an index on fields like email, enum for status fields, and min/max for numbers.
Check the refs. A ref must match the model name you pass to mongoose.model(). Rename it if your collection uses a different name.
The export line uses mongoose.models.User || mongoose.model(...), which stops the “Cannot overwrite model once compiled” error during hot reload in Next.js.
Frequently asked questions
Is my JSON uploaded anywhere?
No. The conversion runs entirely in your browser with JavaScript. Nothing is stored or sent to a server.
Why is the _id field missing from the schema?
Mongoose adds _id to every document automatically, so it is left out. The same goes for __v, and for createdAt/updatedAt when the timestamps option is on.
Can I convert an array of JSON objects?
Yes. Paste an array and the tool merges every object into one schema. Fields that appear in only some objects are treated as optional.
Does it work with TypeScript?
The output is plain JavaScript that also works in TypeScript projects. If you also want types, use the JSON to TypeScript or JSON to Zod tools on this site with the same JSON.
More free tools
-
JSON to Zod Schema Generator
Turn any JSON into a Zod schema plus its TypeScript type, ready to validate API responses and form data.
-
JSON to TypeScript Interface Generator
Generate clean TypeScript interfaces from JSON in one paste, including nested objects, arrays and optional fields.
-
SQL to MongoDB Query Converter
Convert SQL queries to MongoDB find(), aggregate(), updateMany() and more, for mongosh or Mongoose.
-
PAN, Aadhaar, GST and IFSC Validator
Check PAN, Aadhaar, GSTIN, IFSC, PIN code, mobile and UPI formats, with real checksum tests and copy-ready regex.
-
MongoDB Connection String Checker and Builder
Find what’s wrong with a MongoDB URI, from unencoded passwords to SRV ports, or build a correct one for Atlas or a local server.
-
MongoDB ObjectId to Timestamp Converter
See when any MongoDB document was created from its _id, or turn a date into an ObjectId for fast range queries.
