JSONLess
How it works
JSONLess replaces objects like Date into {$type: 'Date', $value : '2016-03-04T07:33:03.000Z'}
before value is stringify and after parse it will revive original object instance
Usage
Use it exacly in the same way as regular JSON
stringify
JSONLess.stringify({name : 'object with not scalar values', date : new Date()});
// '{"name":"object with not scalar values","date":{"$type":"Date","$value":"2016-03-04T07:33:03.000Z"}}'
parse
JSONLess.parse('{"name":"object with not scalar values","date":{"$type":"Date","$value":"2016-03-04T07:33:03.000Z"}}');
// { name: 'object with not scalar values', date: Thu Mar 04 2016 08:33:03 GMT+0100 (CET) }
addHandler
JSONLess.addHandler(Date, (cls, value) => {
return value.toJSON();
}, (cls, value) => {
return new cls(value);
});
now we have added support for Date type