JSON to Mongoose Schema Generator
Turn a JSON object into a Mongoose schema with type-mapped paths, in your browser.
How to use
- Paste or type your JSON into the input box.
- Optionally rename the model (defaults to AutoGenerated).
- Copy the generated schema from the output box.
About this tool
ShowHide
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
BSON Decoder & Extended JSON Viewer
Decode a MongoDB BSON file in your browser: every element type with its type byte, exact int64 and decimal128, and canonical or relaxed Extended JSON.
Developer
JSON → TypeScript Interface
Generate TypeScript interfaces from any JSON sample — types are inferred recursively and named after each key.
Developer
JSON to Zod Schema Generator
Turn a JSON object into a Zod validation schema with inferred types, in your browser.
Developer
JSON to GraphQL Schema (SDL) Converter
Turn a JSON object into GraphQL type definitions (SDL) with scalar mapping, in your browser.
Developer
JSON to Protobuf Schema Converter (proto3)
Turn a JSON object into a proto3 .proto schema with typed fields and nested messages, in your browser.
Developer
JSON Schema Generator
Paste any JSON and get a draft-07 JSON Schema that matches its shape — types inferred, formats detected, required fields filled in.
Developer