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.

Generated code
Runs in your browser. Your JSON is never uploaded.

How to convert JSON to a Mongoose schema

  1. Paste a real document from your API or database into the left box. The sample shows every supported type.
  2. Type your model name, for example User or Order.
  3. Pick the options you want: required fields, trimmed strings, automatic createdAt/updatedAt timestamps, or ES module syntax.
  4. Copy the code or download it as User.model.js and drop it into your models folder.

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.

logo

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome content in your inbox.

We don’t spam! Read our privacy policy for more info.

More free tools