occasionally useful ruby, ubuntu, etc

16Jan/112

HydrateJS: Smarter Javascript Serialization

Finally, here it is: HydrateJS.

It's a library that helps you serialize proper Javascript objects, more than just hash-like objects like JSON.stringify can handle. Anyway, I put a lot of time into the documentation inside the library as well as on the Github Pages link, so check those out! There is also a full suite of specs.

For some of the technical challenges, see my previous post.

Let me know what you think in the comments, and if you're using it, feature requests, etc.

Comments (2) Trackbacks (0)
  1. I am trying to use HydrateJS to serialize an object with circular references and functions. I modified the source as follows for it to serialize functions:
    1)
    case “function”:
    //throw new Error(“can’t serialize functions”);
    //break;
    return uneval(eval(input));

    2)
    case “function”:
    //return this.errorHandler(new Hydrate.NonPrototypeFunctionError(input, name));
    return uneval(eval(input));

    It currently serializes my object just fine.
    However when I try to deserialize it I get the following error:
    No Hydrate resolver found — you should specify one in the Hydrate constructor!

    I’m not sure if that’s caused by my changes or if I’m doing something wrong:
    var serialized = Hydrate.prototype.stringify(object);
    var deserialized = Hydrate.prototype.parse(serialized);


Leave a comment


No trackbacks yet.