1.0.9 • Published 9 years ago

json-schema-utils v1.0.9

Weekly downloads
1
License
ISC
Repository
github
Last release
9 years ago

json-schema-utils

About

  • json-schema-utils is used for generate json schema files from json file
  • use lodash to reduce the codes vs. pure javascript

Usage

  var SchemaUtils = require('json-schema-utils');
  var product = {
    "id": 1,
    "number": 1200,
    "date": "Tue Jul 22 2008 12:11:04 GMT-0700 (Pacific Daylight Time)",
    "dimensions": {
        "length": 7.0,
        "width": 12.0,
        "height": 9.5
    },
    "users": [{
        "name": "steven",
        "age": 28
    }]
};
var schema = SchemaUtils.jsonSchema('Product',product);
//add mongoose schema from json schema
var mongooseSchema = SchemaUtils.mongooseSchemaFromJsonSchema('Product',schema);

var user = {
  "name": "steven",
  "email": "nonumber1989@gmail.com",
  "age": 1000,
  "male": true,
  "skills": ["java", "node"]
 };
  var title = "User";
  var filePath = "./";
  var fileName = filePath + title + ".js";
  processJson(title,user,fileName,function(error,value){
  if(error){
    console.log(error);
  }else{
    console.log(value);
  }
})
//then the file path in 'fileName' will generate a file User.js

Further

  • further will make a mock RESTful server by define some json files then generate CRUD method
  • express + mongoose + mongoDB + json-schema-utils under nodejs
  • input json file on page then generate RESTful service backend
1.0.9

9 years ago

1.0.8

10 years ago

1.0.7

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago