Skip to content

Latest commit

 

History

History
55 lines (45 loc) · 787 Bytes

README.md

File metadata and controls

55 lines (45 loc) · 787 Bytes

Objectify

Given a JSON schema like this...

{
  "title": "Person Schema",
  "type": "object",
  "properties": {
    "firstName": {
      "type": "string"
    },
    "lastName": {
      "type": "string"
    },
    "age": {
      "description": "Age in years",
      "type": "integer",
      "minimum": 0
    }
  },
  "required": ["firstName", "lastName"]
}

Build an object like this...

var person = {
  firstName: "",
  lastName: "",
  age: 0
};

By calling...

var billy =  Objectify.create(schema, { firstName: "billy" });

billy = {
  firstName: "billy",
  lastName: "",
  age: 0
};

Then validate.... using json-schema wrapper...

var isValid = Objectify.validate(schema, billy);
isValid = false // lastName is required