title: Serialize JavaScript object into JSON string
body: <p>I have this JavaScript prototype:</p>
  
  <pre><code>Utils.MyClass1 = function(id, member) {
  this.id = id;
  this.member = member;
  }
  </code></pre>
  
  <p>and I create a new object:</p>
  
  <pre><code>var myobject = new MyClass1("5678999", "text");
  </code></pre>
  
  <p>If I do: </p>
  
  <pre><code>console.log(JSON.stringify(myobject));
  </code></pre>
  
  <p>the result is:</p>
  
  <pre><code>{"id":"5678999", "member":"text"}
  </code></pre>
  
  <p>but I need for the type of the objects to be included in the JSON string, like this:</p>
  
  <pre><code>"MyClass1": { "id":"5678999", "member":"text"} 
  </code></pre>
  
  <p>Is there a fast way to do this using a framework or something? Or do I need to implement a <code>toJson()</code> method in the class and do it manually?</p>