In KnockoutJS is there a way to serialize nested structures of observable arrays to JSON? I am using JSON.stringify, but since it doesn't access the arrays as someObservableArray(), it will not be able to serialize the nested arrays:
Ex: I have an observable array where each item contains an observable array as a property .
Currently I am manually converting it to a standard JS object before calling JSON.stringify, but is there another knockout function that will enable me to convert it to JSON directly
You can use the
ko.toJSON
function which can serialize nested observable structures to JSON:Demo JSFiddle.