Fork me on GitHub

HydrateJS by nanodeath

Make javascript object serialization a snap! Have you found JSON.stringify and JSON.parse insufficient? HydrateJS may be what you're looking for. Note: designed mainly for browsers, but may have a place with server-side code as well. Untested though.

Native JSON serialization (via JSON.stringify) is convenient, but has a couple critical pitfalls:

  1. If your Javascript object is actually an instance of something other than a hash ({}), this information is lost when serializing -- so a method that may have existed pre-serialization on an object won't exist post-deserialization.
  2. Another problem is circular references -- they simply don't work (JSON will throw an exception).
  3. Lastly, object references -- i.e. two elements in an array that point to the exact same object -- aren't deserialized as one might expect.
HydrateJS aims to fix all those.

Dependencies

Only json2.js, but this is bundled with HydrateJS and automatically required into the page as needed.

Install

Limitations

Due to the nature of JavaScript, there are some limitations in order to make serialization work.

License

MIT license -- do what you want.

Authors

Max Aller (nanodeath@gmail.com)

Contact

Max Aller (nanodeath@gmail.com)

Download

You can download this project in either zip or tar formats.

You can also clone the project with Git by running:

$ git clone git://github.com/nanodeath/HydrateJS