Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/smikodanic/mongoose_schema-json
Convert mongoose schema object to JSON, and vice versa.
https://github.com/smikodanic/mongoose_schema-json
Last synced: 15 days ago
JSON representation
Convert mongoose schema object to JSON, and vice versa.
- Host: GitHub
- URL: https://github.com/smikodanic/mongoose_schema-json
- Owner: smikodanic
- Created: 2016-10-14T12:22:26.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2016-10-15T15:14:39.000Z (about 8 years ago)
- Last Synced: 2024-12-19T13:30:54.835Z (21 days ago)
- Language: JavaScript
- Size: 6.84 KB
- Stars: 0
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# mongoose_schema-json
> Convert mongoose schema object to JSON and vice versa.## Installation
`npm install mongoose_schema-json`## Usage
For example when you want to store mongoose schema in mongo database you need to convert it into JSON string.## Example of conversion
```javascript
// mongoose schema in object notationvar schemaObj = {
name: {type: String, lowercase: true},
age: Number,
born: Date,
isActive: Boolean,
fans: [Schema.Types.Mixed],
company_id: Schema.Types.ObjectId
}
``````json
// mongoose schema in JSON notationvar jsonStr = {
"name": {"type": "String", "lowercase": true},
"age": "Number",
"born": "Date",
"isActive": "Boolean",
"fans": ["Schema.Types.Mixed"],
"company_id": "Schema.Types.ObjectId"
}
```## Methods
- schema2json()
- json2schema()```javascript
var convert = require('mongoose_schema-json');var jsonStr = convert.schema2json(schemaObj);
var schemaObj = convert.json2schema(jsonStr);
```## Testing
Test results will be visible in console.
NodeJS must be installed !`$ node test schema2json schema1`
`$ node test json2schema json1`