Add json support to the websock and improved error handling