I want to encode and decode a circular JSON object with circular pointers.
It's not duplicate because I want to encode with circular and decode it. I need circulars objects after decode!
This is just a simple object but I have a complicated object.
var obj = { parent1: { child1: {} } }; obj.parent1.child1.parent = obj.parent1; console.log(JSON.stringify(obj)); // ERROR: Converting circular structure to JSON I try to change pointers to address like:
obj.parent1.child1.parent = '$P$root.parent1$'; and when decode correct it.
But how can I detect which object is a pointer. And how can i get object address?
JSON.parse()to restore whatever reference you used during serialisation. If that's not possible, you'll have to iterate through the parsed object and replace references