base: Add function to convert items which have ostream printers to strings.
websockets: Always return valid json

This changes the websockets layer to always build a TJson object
rather than the mix of hand formatting we had before. Forces
correctness in terms of emitted JSON.