title: Converting multidimensional object array to JSON
body: <p>I have an array of object which i want to convert to a <code>JSON</code> string but i recieve the following error: <code>JavaScript exception :Uncaught TypeError: Converting circular structure to JSON</code></p>
  
  <p>From what i understand this is because there is a loop in references. i've searched here on SO for solutions and someone came up with a 'replace function'. this looked something like this:</p>
  
  <pre><code>var cache = [];
      JSON.stringify(o, function(key, value) {
          if (typeof value === 'object' &amp;&amp; value !== null) {
              if (cache.indexOf(value) !== -1) {
                  // Circular reference found, discard key
                  return;
              }
              // Store value in our collection
              cache.push(value);
          }
          return value;
      });
      cache = null; // Enable garbage collection
  </code></pre>
  
  <p>but using this gives me the following error: <code>Maximum call stack size exceeded</code>.</p>
  
  <p>i think this solution doesn't really fits my needs, because i am not intrested in all the elements ofthe array that i'm trying to convert. These elements are added are 3rd party(google maps) so i have no influence on their child objects.</p>
  
  <p>This is a screenshot of my array object:</p>
  
  <p><img src="https://i.stack.imgur.com/hOIBA.png" alt="enter image description here"></p>
  
  <p>i am only interested in the following items:</p>
  
  <pre><code>Tour
    -id
    -name
    -days :
        -id
        -name
        -markers :
            -dayId
            -title
            -position :
                -nb
                -ob
        -thumbs :
           - 0
           - 1
           - ...
  </code></pre>
  
  <p>because the object array is created by several functions/services/factories is it difficult to make a fiddle or provide some code samples.</p>
  
  <p>Any sugestion how to convert an array like this to JSON is welcome, thanks in advance</p>