JSON to Mongoose Schema Generator
Paste a JSON document and get a Mongoose schema and model: types, nested sub-schemas, arrays, dates and ObjectId refs. Runs in your browser.
Runs in your browser. Nothing is uploaded.
Example
Input:
{"name": "Asif", "email": "a@b.com", "createdAt": "2026-01-01T00:00:00Z", "tags": ["node"], "address": {"city": "Pakpattan"}}Result:
const addressSchema = new Schema({
city: { type: String, required: true },
}, { _id: false });
const userSchema = new Schema({
name: { type: String, required: true },
email: { type: String, required: true },
tags: { type: [String], default: [] },
address: { type: addressSchema, required: true },
}, { timestamps: true });What the generator produces
Paste one document, or an array of documents, from an API response, a mongosh find() or a fixture file. The tool infers a Mongoose schema: strings, numbers and booleans map to String, Number and Boolean; ISO date strings become Date; 24-character hex strings become Schema.Types.ObjectId; nested objects become their own sub-schemas with _id disabled; arrays become typed arrays with an empty default.
You choose the model name, whether fields are marked required, and whether to use the timestamps option. With timestamps on, createdAt and updatedAt are left out of the field list because Mongoose manages them for you. _id and __v are always skipped.
Required fields and arrays of documents
When you paste an array, every item is merged into one shape. A key that is missing from some items is not marked required, because the sample shows it is optional in real data. A key that is null in every sample becomes Schema.Types.Mixed, since there is no type to infer. Review those fields by hand: Mixed turns off casting and change tracking for that path, so call markModified() after changing it, or give it a real type.
Arrays of objects become arrays of a sub-schema, for example items: { type: [itemSchema], default: [] }. Mongoose then validates and casts every element, and the default empty array means new documents never need a null check before push().
From draft to production schema
A schema inferred from samples is a draft. Before shipping it, add what a sample cannot show: unique indexes for emails and slugs, enum lists for status fields, min and max for numbers, ref names on ObjectId fields so populate() works, and compound indexes that match your real queries. Enable strict query mode and validate request bodies at the API edge (for example with Zod) so the database never sees unexpected fields. The generator saves the typing; the constraints are still your design decision.
Frequently asked questions
How does it detect Date and ObjectId fields?
Strings in ISO 8601 date format become Date, and 24-character hexadecimal strings become Schema.Types.ObjectId. Everything else that is text stays String.
Why are nested objects separate schemas?
Sub-schemas keep the model readable and let you reuse them. They are created with { _id: false } so embedded objects do not get their own ids unless you want them.
Does it add indexes?
No. Indexes depend on your queries, so add unique, compound and text indexes yourself after reviewing the draft.
Is my data uploaded?
No. The schema is generated in your browser.
