I can’t use JSON.Stringify because the document object goes many many levels deep. I tried the function over at: http://www.davidpirek.com/blog/object-to-string-how-to-deserialize-json but I get an error _o.hasOwnProperty is not a function. Anyone have any advice or tips?
I can’t use JSON.Stringify because the document object goes many many levels deep. I
Share
You can not serialize ‘document’ to JSON string using JSON.stringify, since it contains circular references. One way to deal with circular references is to implement your own stringify method, which keeps tracks of the circular references and excludes those. (see this answer: How to solve circular reference in json serializer caused by hibernate bidirectional mapping?)
As already said in the comments, do you really need to serialize the document object?
I’ve been working with a similar kind of project (time to advertise: http://hannotaatio.futurice.com) and we do not serialize document object. Instead, relevant information from document object is stored using JavaScript. The code is on Github so feel free to check it out.