Convert Mongoose (JS) schemas to JSON!

Input Mongoose (JavaScript) schemas to generate example JSON! Handy for API tests and mock request bodies.
Mongoose (JS)
Result
 

Convert Mongoose (JS) schemas to JSON!

Build example document JSON from a JavaScript Mongoose schema defined with new Schema({...}). Because the schema definition object itself is parsed, options like { type: String, enum: [...] } or { type: Map, of: Number } and references to other schema variables are followed.

It helps when documenting collections behind an Express + Mongoose API, or explaining to the frontend what a document looks like. Mongoose-specific rules carry over, such as array subdocuments getting _id while nested paths do not.

How to use

  1. Paste the schema file into the Mongoose (JS) box. If sub-schemas live in separate variables, include their definitions in the same input.
  2. A schema not used by any other schema becomes the root document; if there are several, the output is keyed by variable name.
  3. Review the result and copy it with the copy button.

Example

Input (Mongoose · JavaScript)
const variantSchema = new Schema({
  sku: String,
  price: Schema.Types.Decimal128,
  stock: { type: Number, default: 0 },
});

const productSchema = new Schema(
  {
    title: { type: String, required: true },
    variants: [variantSchema],
    dimensions: { width: Number, height: Number },
    labels: { type: Map, of: String },
  },
  { timestamps: { createdAt: "created_at", updatedAt: false } }
);
Output (JSON)
{
  "_id": "507f1f77bcf86cd799439011",
  "title": "",
  "variants": [
    {
      "_id": "507f1f77bcf86cd799439011",
      "sku": "",
      "price": {
        "$numberDecimal": "0"
      },
      "stock": 0
    }
  ],
  "dimensions": {
    "width": 0,
    "height": 0
  },
  "labels": {
    "key": ""
  },
  "created_at": "1970-01-01T00:00:00.000Z",
  "__v": 0
}

variants: [variantSchema] is an array of subdocuments, so each item gets _id, while __v exists only at the top level. dimensions has no type, so it is a nested path without _id, and Decimal128 appears in its toJSON() form, $numberDecimal. The timestamps option renames the field to created_at and disables updatedAt, leaving a single date field.

Supported features

  • The root document gets _id and __v, honoring versionKey: "rev" renames or false.
  • Array subdocuments such as [subSchema] or [{ name: String }] get _id, unless the schema sets { _id: false }.
  • Nested objects without type (address: { city: String }) stay plain objects with no _id.
  • enum arrays give their first value, { type: Map, of: String } gives {"key": ""}, and Schema.Types.Mixed gives null.
  • Schema.Types.ObjectId becomes a sample ObjectId string and Decimal128 becomes {"$numberDecimal": "0"}.
  • Beyond timestamps: true, detailed settings like { createdAt: "created_at", updatedAt: false } are read.
  • Circular references between schemas are cut off with null.

Use cases

Collection docs that stay accurate

When a README or wiki shows an example document per collection, generating it from the schema file keeps the docs from drifting away from the code.

Spotting subdocument `_id`s

Frontends often compare array items without realizing each one carries its own _id. The output makes it clear at which level _id appears.

Explaining responses before populate

Fields with ref are plain ObjectId strings until populated. Use the output as the baseline when describing how a response changes after populate().

Notes and limitations

  • A literal default ("active", 0, true) is used as the sample value. Function defaults such as Date.now are not run, so those fields get the type's placeholder instead.
  • Fields with ref stay ObjectId strings rather than populated objects.
  • An inline new Schema({...}, { _id: false }) written as a field value is converted in place and honors its own options; it does not show up as a separate root entry.
  • Virtuals, toJSON transforms, getters and select: false are not applied.

FAQ

Why does a Decimal128 field come out as an object?

Mongoose's Decimal128 serializes through toJSON() as {"$numberDecimal": "12.50"}. If you send it as a number or string, add a getter or transform to the schema and edit the output to match.

Can I paste TypeScript or NestJS schemas here?

Convert @Schema() classes and interfaces on the Mongoose (TS) to JSON page. This page parses the JavaScript object passed to new Schema().

What if only mongoose.model() is in the file and the schema is elsewhere?

The schema definition must be in the input. Paste the new Schema(...) part along with it.