Convert objects to JSON with circular reference handling
Standard JSON.stringify fails with circular references (objects referencing themselves). Our safe version detects circular structures and replaces them with [Circular *] markers, preventing crashes during debugging and serialization.
When an object references itself directly or indirectly. Example: const obj = {}; obj.self = obj; This breaks JSON.stringify.
It tracks visited objects and replaces circular references with placeholders, ensuring successful serialization.