Converting Circular structure to JSON

1,514 views
Skip to first unread message

Stacey Thornton

unread,
Sep 6, 2011, 8:37:21 AM9/6/11
to knock...@googlegroups.com
In doing some research about how to create object graphs with parent/child associations, I ran across this error from an example in another discussion.

(Updated jsFiddle : http://jsfiddle.net/ciel/hzDZE/)


1544Uncaught Error: Unable to parse bindings. Message: TypeError: Converting circular structure to JSON; Bindings value: text: ko.toJSON(viewModel)

Any idea how to deal with this?

Stacey Thornton

unread,
Sep 6, 2011, 8:55:52 AM9/6/11
to knock...@googlegroups.com
Sorry, forgot to add that the error is in the debugging console. I know why this is happening, of course. The parent references the children references the parent etc. and so serialization would cause an infinite loop.

I have tried using the [name].prototype.toJSON method to exclude the parent from serialization, but it does not seem to work.

dg...@brq.com

unread,
Sep 24, 2012, 1:34:00 PM9/24/12
to knock...@googlegroups.com
Hi...facing the same issue...any idea?

tim.f...@3smobile.com

unread,
Sep 24, 2012, 2:16:23 PM9/24/12
to knock...@googlegroups.com, dg...@brq.com
The problem is obviously the parent-binding.  Perhaps there is a way you could remove it.  See how this example does a tree structure:


-tim

rajeev....@gmail.com

unread,
Oct 7, 2014, 3:31:29 AM10/7/14
to knock...@googlegroups.com, dg...@brq.com, tim.f...@3smobile.com

Facing same problem. and as per some structuring I can't removing this circular reference. Any solution ?

Ralph Becket

unread,
Oct 7, 2014, 6:50:08 PM10/7/14
to knock...@googlegroups.com, dg...@brq.com, tim.f...@3smobile.com, rajeev....@gmail.com
Clearly you need to create a cycle-free version of your data structure prior to calling ko.toJSON.

Here's an example of how you might do that: http://jsfiddle.net/hzDZE/4/ (note the acyclicRowModel function).
Reply all
Reply to author
Forward
0 new messages