title: Deserialize a JSON object in Fabric.js
body: <p>I am developping a collaborative whiteboard using fabricjs. When a user creates a new fabric object , I serialize it and send it to all other users. </p>
  
  <pre><code>var rect = new fabric.Rect();
  canvas.add(rect);  
  socket.emit("newObject", JSON.stringify(rect)); // sends the object to other users
  </code></pre>
  
  <p>When those users receive the serialized object, it should be deserialized and added to their canvas. What is the best way to do this? I was not able to find a function that deserializes a single object, only the whole canvas (loadFromJSON), so I implemented an unelegant solution:</p>
  
  <pre><code>function drawRoomObjects(roomObjects){
    var canvasString = "{\"objects\":[";
    for(var roomObjectKey in roomObjects){
      canvasString += roomObjects[roomObjectKey];
    }
    canvasString += "], \"background\":\"\"}";
    var tmpCanvas = new fabric.Canvas();
    tmpCanvas.loadFromJSON(canvasString);
    for(var k in tmpCanvas.getObjects()) {
      canvas.add(tmpCanvas._objects[k]);
    }
    canvas.renderAll();
  }
  </code></pre>
  
  <p>Any suggestions for a better way to do it?</p>