2

I am able to convert cyclic Object to JSON. Now, i want to convert JSON to cyclic Object

//Cyclic to JSON conversion which works fine

  <script>
    var seatObj;
    seen = []; 
            var replacer = function(key, value) {
              if (value != null && typeof value == "object") {
                if (seen.indexOf(value) >= 0) {
                  return;
                }
                seen.push(value);
              }
              return value;
            };
     seatObj = JSON.stringify(obj.part.data, replacer);
    </script>
  • 2
    Since your conversion to JSON threw away any information about the cyclic dependency, you cannot restore it; the information is simply lost. – Ingo Bürk May 10 '19 at 11:53
  • I found this link for you https://stackoverflow.com/a/22723563/10035556 – Mayur May 10 '19 at 11:57

1 Answers1

0

If you want to restore your cyclic information, you need to retain it somehow. Traditionally you would generate or keep track of existing object ids to retain the information in your json output.

Slawomir Chodnicki
  • 1,525
  • 11
  • 16