Useful for dumping an object to the view for debugging.

ko.bindingHandlers.toJson= {
    update: function(element, valueAccessor){
        return ko.bindingHandlers.text.update(element,function(){
            return ko.toJSON(valueAccessor(), null, 2);
        });
    }
};

Usage - Show entire view-model:

<pre data-bind="toJson: $root"></pre>

Usage - Show current data context:

<pre data-bind="toJson: $data"></pre>