I have an object that contains circular references, and I would like to look at its JSON representation. For example, if I create this object:
var myObject = {member:{}}; myObject.member.child = {}; myObject.member.child.parent = myObject.member;
and try to call
JSON.stringify(myObject);
I get a "too much recursion" error, which is not surprising. The "child" object has a link to its "parent", and the parent has a link to its child. The JSON representation does not have to be absolutely accurate, since I use it only for debugging, and not for sending data to the server or serializing the object to a file or something like that. Is there a way to tell JSON.stringify to simply ignore certain properties (in this case, the parent property of the child) so that I get:
{ "member" : { "child" : {} } }
The closest I can think of is to use the getChild() and getParent() methods instead of simple members, because JSON.stringify ignores any properties that are functions, but I would prefer not to do this if I don't have k.
source share