title: Excluding object properties while json-stringifying array object
body: <p>hey I have a array object something like this</p>
  
  <pre><code>[{
      public: "public",
      private: "private",
      [{
          properties: {...
          },
          instance: {.....
          }
      }, {...
      }, {...
      }]
  }, {...
  }, {....
  }]
  </code></pre>
  
  <p>Here the outer most array contains object of class A, which has a some public props, some private porps and it also contains an array which contains object of class B, which also contains some public and private fields.</p>
  
  <p>so basically this is my hierarchy</p>
  
  <pre><code>array = [A1,A2,A3,A4,....]//object of A
  
  var A = function(){
    var Const = function(){
      this.public_prop;
      this.private_prop;
      this.list = [B1,B2,B3,B4]// objects of B
    }
   //.........
   return Const;
  }();
  
  var B = function(){
  
    var Const = function(){
     this.public_prop;
     this.private_prop;
    }
   //.........
   return Const;
  }();
  </code></pre>
  
  <p>Now while stringifying(serialzing) it I want to only include public prop and the arrays in the serialized string.</p>
  
  <p>for example for the above JSON representation i want something like this</p>
  
  <pre><code>[{
          public: "public",
          [{
              properties: {...
              }
          }, {...
          }, {...
          }]
      }, {...
      }, {....
      }]
  </code></pre>
  
  <p>now i can create a function <em>getState() in each class</em> which will only return fields which needs to be stringified, but i cannot seem to find a way to make the native implementation of JSON.stringify call the method before serializing it.  Is there some way of accomplishing this?</p>
  
  <p>I refered <a href="https://stackoverflow.com/questions/4910567/json-stringify-how-to-exclude-certain-fields-from-the-json-string">Hide certain values in output from JSON.stringify()</a>, but it only explains how to exclude simple numeric or string prop in single hierarchy, but how to exclude props in multiple hierarchy?</p>
  
  <p><em>Note:All my classes follow module-pattern</em></p>