Skip to content

Instantly share code, notes, and snippets.

@misablaha
Created July 23, 2012 15:04
Show Gist options
  • Save misablaha/3164125 to your computer and use it in GitHub Desktop.
Save misablaha/3164125 to your computer and use it in GitHub Desktop.
json_validate
validate = require('./node_modules/commonjs-utils/lib/json-schema.js').validate
schema =
type: "object"
properties:
users:
type: "object"
items:
type: "object"
properties:
id: {type: "number"}
username: {type: "string"}
numPosts: {type: "number"}
realName: {type: "string", optional: true}
object =
users: [
{id: 1, username: 'mr. stone', numPosts: 5, age: 34 }
{id: 2, username: 'mr. wood', }
]
console.log validate object, schema
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment