Registry / database / json-schema-to-mongoose

json-schema-to-mongoose

JSON →
library0.2.2jsnpmunverified

A library for converting JSON Schema to Mongoose Schema, written in TypeScript. Current stable version is 0.2.2. Release cadence is low (last update likely a few years ago). Key differentiator: single-purpose conversion from JSON Schema to Mongoose, supporting patterns like $ref and default values. Note: requires manual type reference for TypeScript, and uses default export via require.

npm install json-schema-to-mongoose
INSTALL
IMPORT
SIG · JSON-SCHEMA-TO-MON
J
json-schema-to-mongoose
databasejavascriptv0.2.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createMongooseSchema
import createMongooseSchema = require('json-schema-to-mongoose')
import { createMongooseSchema } from 'json-schema-to-mongoose'
The library exports a single function via default export in a CommonJS style; use TypeScript's import = require syntax or plain require.
default
const createMongooseSchema = require('json-schema-to-mongoose')
import createMongooseSchema from 'json-schema-to-mongoose'
For plain JavaScript or older TypeScript, use require; ES import syntax may not work due to lack of ESM support.
TypeScript declaration
/// <reference path="../node_modules/json-schema-to-mongoose/json-schema-to-mongoose.d.ts" />
import type ...
The library provides a .d.ts file that must be referenced explicitly with a triple-slash directive for TypeScript to recognize types.

Converts a JSON Schema with a $ref reference to a Mongoose schema object, using the library's main function.

import createMongooseSchema = require('json-schema-to-mongoose'); const refs = { yep: { type: 'string', pattern: '^\\d{3}$' } }; const schema = { type: 'object', properties: { id: { $ref: 'yep' }, address: { type: 'object', properties: { street: { type: 'string', default: '44', pattern: '^\\d{2}$' }, } } } }; const mongooseSchema = createMongooseSchema(refs, schema); console.log(JSON.stringify(mongooseSchema, null, 2));
Debug
Known issues
gotchaTypeScript usage requires explicit triple-slash reference to declaration file.
fix
Add /// <reference path=".../json-schema-to-mongoose.d.ts" /> at the top of your TypeScript file.
affects: 0.x
gotchaImport syntax must use import = require for TypeScript; ES module import may fail.
fix
Use `import createMongooseSchema = require('json-schema-to-mongoose')` or `const createMongooseSchema = require('json-schema-to-mongoose')`.
affects: 0.x
gotchaDefault values with function references (e.g., '[Function=Date.now]') are treated as strings, not executed.
fix
Pass functions as strings or handle after conversion; library does not evaluate function strings.
affects: 0.x
Errors
Common errors & fixes
Cannot find module 'json-schema-to-mongoose'
Module not installed or incorrect import path.
fix
Run `npm install json-schema-to-mongoose --save` and ensure import path is correct.
TS2307: Cannot find module 'json-schema-to-mongoose' or its corresponding type declarations.
TypeScript cannot locate types; missing triple-slash reference or typeRoots config.
fix
Add `/// <reference path="node_modules/json-schema-to-mongoose/json-schema-to-mongoose.d.ts" />` or install @types if available.
TypeError: createMongooseSchema is not a function
Incorrect import: using named import instead of default import.
fix
Use `import createMongooseSchema = require('json-schema-to-mongoose')` instead of `import { createMongooseSchema } from '...'`.
Upgrade
Version history
0.2.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Resources
json-schema-to-mongoose — npm install json-schema-to-mongoose · libregistry