var Swiz = require('swiz').Swiz;
var Valve = require('swiz').Valve;
var Chain = require('swiz').Chain;
var defToValve = require('swiz').defToValve;

// Note: There's one set of definitions that control both serialization
// and validation
var def = {
'Node': [
  ['key', {'val' : new Chain()}],
  ['ip_address_v4', {'val' : new Chain().isIP()}]
]};

var validity = defToValve(def);
var schema = validity.Node;
var v = new Valve(schema);

// Generic payload
var CreatePayload = {
  key: '1234',
  ip_address_v4: '1.2.0.4'
};

console.log('validate a payload:\n');

// Validate the generic payload
v.check(CreatePayload, function(cleaned, err) {
  var swiz = new Swiz(def);
  if (err) {
    console.error(err);
  } else {
    console.log('\n\nserialize an object\n');
    cleaned.getSerializerType = function() {return 'Node';};
    sw.serialize(validate.SERIALIZATION.SERIALIZATION_JSON, 1, cleaned,
      function(err, results) {
        console.log(results);
      }
    );
  }
});

@@ -1,12 +1,46 @@
+var swiz = require('./lib/swiz');%0A
 var Swiz = r
@@ -43,24 +43,30 @@
  = require('
+./lib/
 swiz').Swiz;
@@ -83,24 +83,30 @@
  = require('
+./lib/
 swiz').Valve
@@ -124,24 +124,30 @@
  = require('
+./lib/
 swiz').Chain
@@ -174,16 +174,22 @@
 equire('
+./lib/
 swiz').d
@@ -198,16 +198,68 @@
 ToValve;
+%0Avar O = swiz.struct.Obj;%0Avar F = swiz.struct.Field;
 %0A%0A// Not
@@ -356,23 +356,56 @@
 f = 
-%7B%0A'Node
+%5B%0A  O('Node',%0A    %7B%0A      'fields
 ': %5B%0A  
+ 
-%5B
+     F(
 'key
@@ -432,14 +432,21 @@
 n()%7D
-%5D
+)
 ,%0A  
-%5B
+      F(
 'ip_
@@ -490,12 +490,52 @@
 P()%7D
-%5D%0A%5D%7D
+)%0A      %5D,%0A%0A      'plural': 'nodes'%0A    %7D)%0A%5D
 ;%0A%0Av
@@ -835,18 +835,16 @@
   var sw
-iz
  = new S
@@ -1025,24 +1025,20 @@
 rialize(
-validate
+swiz
 .SERIALI

Update demo.js.