{"id":47312,"library":"convert-json-schema-to-mongoose","title":"convert-json-schema-to-mongoose","description":"Converts JSON Schema definitions into Mongoose 5 schema objects. Version 0.3.2 is the latest stable release (no recent updates). It handles nested objects, references ($ref), defaults, and formats. Written in TypeScript with type declarations. Alternatives exist but none have more recent activity.","status":"active","version":"0.3.2","language":"javascript","source_language":"en","source_url":"https://github.com/kristianmandrup/convert-json-schema-to-mongoose","tags":["javascript","json","schema","convert","mongo","mongoose"],"install":[{"cmd":"npm install convert-json-schema-to-mongoose","lang":"bash","label":"npm"},{"cmd":"yarn add convert-json-schema-to-mongoose","lang":"bash","label":"yarn"},{"cmd":"pnpm add convert-json-schema-to-mongoose","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This is a named export, not default.","wrong":"import createMongooseSchema from 'convert-json-schema-to-mongoose'","symbol":"createMongooseSchema","correct":"import { createMongooseSchema } from 'convert-json-schema-to-mongoose'"},{"note":"CJS destructuring works; the package has no default export.","wrong":"const createMongooseSchema = require('convert-json-schema-to-mongoose').default","symbol":"createMongooseSchema (CommonJS)","correct":"const { createMongooseSchema } = require('convert-json-schema-to-mongoose')"},{"note":"MongooseSchema may be a type-only export; use type import to avoid runtime issues.","wrong":"import { MongooseSchema } from 'convert-json-schema-to-mongoose'","symbol":"TypeScript types","correct":"import type { MongooseSchema } from 'convert-json-schema-to-mongoose'"}],"quickstart":{"code":"import { createMongooseSchema } from 'convert-json-schema-to-mongoose';\n\nconst refs = {\n  yep: { type: 'string', pattern: '^\\\\d{3}$' }\n};\n\nconst schema = {\n  type: 'object',\n  properties: {\n    id: { $ref: 'yep' },\n    name: { type: 'string', default: 'foo' }\n  }\n};\n\nconst mongooseSchema = createMongooseSchema(refs, schema);\nconsole.log(mongooseSchema);\n// Output: { id: { type: [Function: String] }, name: { type: [Function: String], default: 'foo' } }","lang":"typescript","description":"Converts a JSON Schema with a $ref and a property with default into a Mongoose schema object."},"warnings":[{"fix":"Provide an object for refs (even if empty) as first argument, and schema as second.","message":"The function signature expects two arguments: refs and schema. Passing only one argument (schema) will cause an error.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use string format '[Function=Date.now]' instead of the actual function.","message":"Defaults that are functions (e.g., Date.now) must be passed as strings '[Function=Date.now]' to be interpreted correctly.","severity":"gotcha","affected_versions":">=0.3.0"},{"fix":"Consider using a more recent library or manually update the schema for Mongoose 6+.","message":"The package targets Mongoose 5; Mongoose 6+ has breaking changes (e.g., strictQuery default changed). The generated schema may not be compatible with Mongoose 6+.","severity":"deprecated","affected_versions":">=0.1.0"},{"fix":"Add a declaration file or cast the result to 'any' if needed.","message":"The package has no type definitions for MongooseSchema; TypeScript users may need to declare their own types.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"search_vec":"'0.3.2':17 '5':13 'activ':48 'altern':41 'convert':2,7,52 'convert-json-schema-to-mongoos':1 'declar':40 'default':32 'definit':10 'exist':42 'format':34 'handl':27 'javascript':49 'json':3,8,50 'latest':20 'mongo':53 'mongoos':6,12,54 'nest':28 'none':44 'object':15,29 'recent':24,47 'ref':31 'refer':30 'releas':22 'schema':4,9,14,51 'stabl':21 'type':39 'typescript':37 'updat':25 'version':16 'written':35","created_at":"2026-06-07T16:50:53.064711+00:00","updated_at":"2026-06-07T16:50:53.064711+00:00","problems":[{"fix":"Call createMongooseSchema(refs, schema) where refs is an object (can be empty {}).","cause":"Calling createMongooseSchema without providing refs as first argument.","error":"TypeError: Cannot read properties of undefined (reading 'properties')"},{"fix":"Ensure the schema has { type: 'object' } at the root.","cause":"The schema object must have a 'type' property set to 'object'.","error":"Error: Schema is not valid JSON Schema object"},{"fix":"Include all referenced schemas in the refs object.","cause":"One of the $ref references is missing in the refs object.","error":"TypeError: Cannot use 'in' operator to search for '__id' in undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/kristianmandrup/convert-json-schema-to-mongoose","github":"https://github.com/kristianmandrup/convert-json-schema-to-mongoose","docs":null,"changelog":null,"pypi":null,"npm":"convert-json-schema-to-mongoose","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}