0.2.3 • Published 12 years ago

cereal v0.2.3

Weekly downloads
42
License
-
Repository
github
Last release
12 years ago

Cereal

Serialisation Library for JavaScript that respects object aliases.

Can be used either client-side or in NodeJS.

What does it solve?

Aliases

var x = {};
var y = {a: x, b: x};

If you take the above and then do JSON.parse(JSON.stringify(y)) then you will lose the alias to x: what you'll get back will be {a: {}, b: {}}.

If you instead do Cereal.parse(Cereal.stringify(y)) then you'll get back the correct object shape, with both a and b pointing to the same object.

Loops

JSON can't cope with cyclical data structures. Cereal can.

var x = {};
x.x = x;

JSON will blow up if you try to stringify(x). Cereal will work correctly.

Anything else?

JSON invokes toJSON on an object before encoding it. Analogously to this, Cereal invokes invoking a cerealise function if it exists and encoding what is returned from that.

Note that Cereal first rewrites the object structure to something without loops or aliases (but from which the loops and aliases can be reconstructed) and then it just uses normal JSON encoding on the result. And vice-versa.

As a result, Cereal will ignore everything that JSON would ignore too. Thus as normal, you lose functions, prototypes etc etc.

0.2.3

12 years ago

0.2.2

12 years ago

0.2.1

12 years ago

0.2.0

12 years ago

0.1.1

12 years ago

0.1.0

12 years ago

0.0.7

12 years ago

0.0.6

12 years ago

0.0.5

12 years ago

0.0.4

12 years ago

0.0.3

12 years ago

0.0.2

12 years ago

0.0.1

12 years ago