Skip to content
AZ Tools

JSON to Mongoose Schema Generator

Turn a JSON object into a Mongoose schema with type-mapped paths, in your browser.

Mongoose schema

How to use

  1. Paste or type your JSON into the input box.
  2. Optionally rename the model (defaults to AutoGenerated).
  3. Copy the generated schema from the output box.

About this tool

Show

Paste any JSON object and get a ready-to-use Mongoose schema with each path mapped to a schema type, nested objects inlined as subdocuments, and a model export at the bottom. Strings, numbers, and booleans map directly; a null becomes Schema.Types.Mixed and an empty array becomes [Schema.Types.Mixed], because one sample cannot say what belongs there. One mapping deserves a second look: JSON has no date type, so an ISO timestamp arrives as a string and is typed String — switch those paths to Date yourself if you want Mongoose to cast and query them as dates. Mongoose also adds _id on its own, so you do not need to declare it. Everything runs locally in your browser — your JSON is never uploaded.

Frequently asked questions

How are numbers typed?

All JSON numbers map to Number — Mongoose does not distinguish integers from floats. Use a custom validator if you need integer-only paths.

What happens with null or empty arrays?

null maps to Schema.Types.Mixed and empty arrays to [Schema.Types.Mixed], since their type can't be inferred from the sample.

How are nested objects handled?

Nested objects are inlined as nested path definitions (subdocuments). An empty object becomes {}.

Is my JSON sent anywhere?

No. Conversion happens entirely in your browser; nothing is uploaded.

My timestamps came out as String — is that right?

It is what the sample showed. JSON has no date type, so an ISO timestamp arrives as text and is typed String. Change those paths to Date yourself if you want Mongoose to cast them, index them and compare them as dates rather than lexically.

Do I need to declare _id?

No. Mongoose adds an ObjectId _id to every schema on its own, and adding your own path of that name would collide with it. Pass timestamps: true to the schema options if you also want createdAt and updatedAt maintained for you.

Related tools