I'm trying to stringify(...) an object in Chrome, and I keep getting a "Converting circular structure to JSON" message, despite the fact that (as far as I know) no such structure exists.
I've been over the code a dozen times and can't find any circular references whatsoever. Is there any way to get Chrome to tell me what it's bitching about beyond this painfully useless error message?
You can use
dojox.json.ref
to find circular references. This code prints json representation of yourobjectWithCircularReferences
:Any occurence of "$ref" substring in its output to console will help you locate circular references. You can alternatively pipe this json output to global variable ZZZ like this if you wish:
And of course you need to include dojo library beforehand. In an html file:
In firebug console:
In Chrome console:
Pardon me if this is too obvious. At the time of writing, I dont know what you have tried.
insert
replacing 'the object' with the object you are passing to
JSON.stringify()
insert this line before the
JSON.stringify
calland look in the console log (shift control J) for the object. In the console log the object will be tagged with a ">" symbol which can be clicked to expand to the fields.
It is complaining about an object that has pointers into itself, like this kind of object: