Custom function for Json to String function - Javascript JSon

Javascript examples for JSon:JSon Object

Description

Custom function for Json to String function

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=( function() {/* w  ww . j  a v  a2 s  .  c  om*/
obj = { x:555, y: "hi" }
obj.myself = obj
seen = []
json = JSON.stringify(obj, function(key, val) {
   if (typeof val == "object") {
        if (seen.indexOf(val) >= 0)
            return;
        seen.push(val);
    }
    return val;
})
console.log(json);
    });

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials