JSON to Mongoose Schema

JSON → Mongoose schema. 24-character hex strings become ObjectId (with a ref inferred from an xxxId field name), ISO-8601 strings become Date, and _id is left to Mongo.

JSON to Mongoose Schema — Free Online Tool

Generates a Mongoose schema and model from a JSON sample, mapping values to String, Number, Boolean, Date and nested subdocuments, recognizing 24-character hex strings as ObjectId references and ISO-8601 strings as Date, wrapping arrays in [] and adding timestamps, useful for bootstrapping MongoDB collections from an example document.

How to use the JSON to Mongoose Schema

  • Open the tool above — it runs entirely in your browser, so your input never leaves this page.
  • Paste or type your input into the field, then press the relevant button (e.g. Encode / Decode, Generate, or Convert).
  • Copy the result from the output area with the copy button orCtrl/Cmd + C.
  • No signup, no upload, and no tracking — repeat as often as you need.

Frequently asked questions

Why did a string become ObjectId instead of String?

A 24-character hexadecimal string is the canonical Mongo ObjectId representation, so it is typed Schema.Types.ObjectId. If the field name ends in Id or _id, a ref to the inferred collection is added too — remove it if the field is a plain identifier rather than a reference.

Why is _id missing from the schema?

Mongoose adds _id automatically. Declaring it again is a common source of casting bugs, so it is skipped — add it back explicitly only when you need a custom _id type.

How are nested objects handled?

They become inline subdocument definitions. If you want a separate collection with a reference instead, replace the nested block with { type: Schema.Types.ObjectId, ref: 'Name' }.

Free & private — why use this JSON to Mongoose Schema

The JSON to Mongoose Schema runs 100% client-side in your browser. Your data is never uploaded to a server, no account is required, and the tool is completely free. It works offline once the page has loaded and is part of a growing collection of privacy-first developer utilities.

More json tools