Skip to content
{ }JSON Formatter

JSON to Mongoose Schema

Generate a Mongoose schema from a JSON sample — field types inferred, nested subdocuments inline, required set for fields present in every record.

Input
Output
Paste input and press Generate Mongoose.

From a document to a schema

Modeling a MongoDB collection in Mongoose? Paste a representative document and this tool infers the new Schema({ … }): strings become String, numbers Number, booleans Boolean, arrays become [Type], and nested objects become inline subdocuments. It's one inline schema, so there's nothing to wire up — paste and use.

required, inferred from the data

A scalar field is marked { type: …, required: true } only when it appears in every record of the sample and is never null; anything that can be missing or null is left as a plain type. Untyped or mixed values map to Schema.Types.Mixed. Nested subdocuments and arrays are emitted structurally so you can add validators, defaults and refs where you need them.

Finish the model

Wrap the schema with mongoose.model("Name", schema), add indexes, defaults, ref relations and custom validators to complete it. Need a SQL table or a Prisma model instead? Try JSON to SQL Schema or JSON to Prisma; for a runtime validator, JSON to Zod.

Frequently asked questions

How is required decided?

A scalar field is emitted as { type: …, required: true } only when it is present in every record of the sample and never null. Fields that are missing anywhere, or null, are left as a plain type so they are optional.

How are nested objects and arrays handled?

Nested objects become inline subdocuments ({ … }), and arrays become typed arrays ([String], [Number], or an array of subdocuments). Everything is emitted in one Schema so there is nothing to import between pieces.

What is Schema.Types.Mixed in the output?

Mongoose has no single "anything" scalar, so untyped or genuinely mixed values (and always-null fields) map to Schema.Types.Mixed. Replace it with a concrete type once you know the shape.

Is this the whole model?

It is the schema definition. Wrap it with mongoose.model("Name", schema) and add indexes, defaults, ref relations and validators. The field types and required flags — the tedious part — are done for you.