Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
55
rated 0 times [  57] [ 2]  / answers: 1 / hits: 25112  / 13 Years ago, wed, march 23, 2011, 12:00:00

For debugging I want to serialize javascript objects with JSON.stringify(myobject). But this gives:



TypeError: Converting circular structure to JSON


Is there a way to prevent this, by for instance pruning the output tree?



Some more background:



I want to collect some data on different objects and see what is going on, and why a feature works for one situation but not for another. By comparing outputs I hope to be able to find differences which explains why it is not working in another situation.
I'm using jquery and my debug horse is called chrome. If there are better alternatives for doing this type of debugging activities I'm also very much interested!



Cheers,
jeroen.


More From » json

 Answers
22

JSON.stringify(obj) does not support circular referencing such as:



var car = {}
car.myself = car;
JSON.stringify(car);


However dojox.json.ref does support circular referencing, if you wanted to explore another option.



However if your purposes are strictly to debug, I'd suggest using the built in browser debugger such as Chrome's, IE's or Firebug(for firefox).


[#93111] Tuesday, March 22, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
deannaalysonl

Total Points: 703
Total Questions: 101
Total Answers: 115

Location: Saint Helena
Member since Tue, Nov 3, 2020
4 Years ago
deannaalysonl questions
;