Type-accurate serialization of javascript objects