Skip to content
100% local

JSON to Mongoose schema

Turn a JSON sample into a ready-to-use Mongoose schema and model.

Input
Output

JSON to Mongoose schema

Paste a sample JSON document — a single object or an array of them — and this tool infers the shape and generates a working new mongoose.Schema() definition with a model export. It is built for the moment you have a JSON payload from an API, a seed file or an old database dump and need a Mongoose model, without typing every field by hand.

The tool reads real values to choose real types: strings become String, numbers become Number, an ISO-looking date string becomes Date, and a field whose name ends in "Id" (or the array form "…Ids") becomes an ObjectId reference, since that is how a hand-written schema would model it. Nested objects become their own new mongoose.Schema({...}) inside the parent, and an array of objects becomes an array of that nested schema. Options handle the rest: name the model, mark scalar fields as required, carry the sample's own values over as defaults, toggle the timestamps option, decide whether subdocuments keep their own _id, and switch "Id"-suffixed fields between ObjectId and plain String. Pick CommonJS or ES module syntax, and optionally add a matching TypeScript interface below the model.

Feeding an array of sample documents instead of one lets the tool notice fields present in only some of them, useful when real data is not perfectly uniform — those become optional in the generated interface. Windows and Unix line endings are treated identically, and input too large to process comfortably is reported instead of freezing the tab. The tally under the output shows the field count, the nested-schema count and the character count.

Everything runs locally in your browser — the JSON you paste, which may contain real records, is never uploaded anywhere. When the schema looks right, copy it, download it as a .txt file to paste into your own .js or .ts file, or send the output back into the input to refine it further.

FAQ

What types does it detect?
String, Number, Boolean, Date (from ISO-looking date strings), ObjectId (for fields whose name ends in "Id" or "Ids"), nested schemas for objects, and arrays of any of those. A field with no reliable type, or one whose type disagrees between sample documents, becomes mongoose.Schema.Types.Mixed.
Can I paste more than one sample document?
Yes. Paste an array of objects and the tool merges them: a field present in only some of them is treated as optional in the generated TypeScript interface, and a field whose type differs between documents falls back to Mixed.
What does "Include _id in subdocuments" control?
Mongoose gives every embedded subdocument its own _id by default. Turning this off adds { _id: false } to each generated nested schema, which is the common choice for subdocuments that are never queried on their own.
Why does a field like "userId" become an ObjectId?
A field name ending in "Id" (singular) or "Ids" (an array of references) is almost always a reference to another document, so the tool renders it as mongoose.Schema.Types.ObjectId instead of String. Turn off "Use ObjectId for 'Id' fields" if you want plain strings instead.
Is my JSON uploaded anywhere?
No. Schema generation runs entirely in your browser — your JSON, including any real records it contains, never leaves your device.