title: Stringify (convert to JSON) a JavaScript object with circular reference
body: <p>I've got a JavaScript object definition which contains a circular reference: it has a property that references the parent object.</p>
  
  <p>It also has functions that I don't want to be passed through to the server. How would I serialize and deserialize these objects?</p>
  
  <p>I've read that the best method to do this is to use Douglas Crockford's stringify. However, I'm getting the following error in Chrome:</p>
  
  <blockquote>
    <p>TypeError: Converting circular structure to JSON</p>
  </blockquote>
  
  <p>The code:</p>
  
  <pre><code>function finger(xid, xparent){
      this.id = xid;
      this.xparent;
      //other attributes
  }
  
  function arm(xid, xparent){
      this.id = xid;
      this.parent = xparent;
      this.fingers = [];
  
      //other attributes
  
      this.moveArm = function() {
          //moveArm function details - not included in this testcase
          alert("moveArm Executed");
      }
  }
  
   function person(xid, xparent, xname){
      this.id = xid;
      this.parent = xparent;
      this.name = xname
      this.arms = []
  
      this.createArms = function () {
          this.arms[this.arms.length] = new arm(this.id, this);
      }
  }
  
  function group(xid, xparent){
      this.id = xid;
      this.parent = xparent;
      this.people = [];
      that = this;
  
      this.createPerson = function () {
          this.people[this.people.length] = new person(this.people.length, this, "someName");
          //other commands
      }
  
      this.saveGroup = function () {
          alert(JSON.stringify(that.people));
      }
  }
  </code></pre>
  
  <p>This is a test case that I created for this question. There are errors within this code but essentially I have objects within objects, and a reference passed to each object to show what the parent object is when the object is created. Each object also contains functions, which I don't want stringified. I just want the properties such as the <code>Person.Name</code>.</p>
  
  <p>How do I serialize before sending to the server and deserialize it assuming that the same JSON is passed back?</p>