title: How to stringify objects through JSON's replacer function?
body: <p>Here is my code:</p>
  <pre><code>BAD = {
            &quot;a&quot;: &quot;2&quot;,
            &quot;b&quot;: 1,
            &quot;c&quot;: &quot;Nexus&quot;,
            &quot;d&quot;: &quot;Alligator&quot;,
            &quot;e&quot;: 5,
            &quot;f&quot;: 1431807036,
            &quot;g&quot;: {
                      &quot;2&quot;: {
                              &quot;w&quot;: 17,
                              &quot;b&quot;: 5
                           }
                 }
        }
  
  console.log(JSON.stringify(BAD, ['a', 'b', 'c', 'd', 'e', 'g']));
  </code></pre>
  <p><a href="http://jsfiddle.net/whv7x6xc/1/" rel="nofollow noreferrer">http://jsfiddle.net/whv7x6xc/1/</a></p>
  <p>The keys <code>a</code>, <code>b</code>, <code>c</code>, <code>d</code>, <code>e</code>, and <code>g</code> are the only ones being stringified which is nice, but there is one problem. It's ignoring the object that is assigned to <code>g</code>.</p>
  <p><img src="https://i.stack.imgur.com/Hv6n9.png" alt="enter image description here" /></p>
  <p>But, if you do: <code>console.log(JSON.stringify(BAD));</code> it shows the proper stringified version.</p>
  <p>Edit: <code>w</code> and <code>b</code> are dynamic and changed periodically (come and go) though, so I cannot just hard-code them in.</p>